Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/hotspot/share/logging/logDecorators.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -100,7 +100,9 @@ bool LogDecorators::parse(const char* decorator_args, outputStream* errstream) {
break;
}
tmp_decorators |= mask(d);
token = comma_pos + 1;
if (comma_pos != nullptr) {
token = comma_pos + 1;
}
} while (comma_pos != nullptr);
os::free(args_copy);
if (result) {
Expand Down
6 changes: 4 additions & 2 deletions src/hotspot/share/logging/logSelection.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -151,7 +151,9 @@ static LogSelection parse_internal(char *str, outputStream* errstream) {
return LogSelection::Invalid;
}
tags[ntags++] = tag;
cur_tag = plus_pos + 1;
if (plus_pos != nullptr) {
cur_tag = plus_pos + 1;
}
} while (plus_pos != nullptr);

for (size_t i = 0; i < ntags; i++) {
Expand Down
8 changes: 6 additions & 2 deletions src/hotspot/share/logging/logSelectionList.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -69,7 +69,7 @@ bool LogSelectionList::parse(const char* str, outputStream* errstream) {
}
char* copy = os::strdup_check_oom(str, mtLogging);
// Split string on commas
for (char *comma_pos = copy, *cur = copy; success && comma_pos != nullptr; cur = comma_pos + 1) {
for (char *comma_pos = copy, *cur = copy; success; cur = comma_pos + 1) {
if (_nselections == MaxSelections) {
if (errstream != nullptr) {
errstream->print_cr("Can not have more than " SIZE_FORMAT " log selections in a single configuration.",
Expand All @@ -90,6 +90,10 @@ bool LogSelectionList::parse(const char* str, outputStream* errstream) {
break;
}
_selections[_nselections++] = selection;

if (comma_pos == nullptr) {
break;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this check is not necessary here since it is checked in the for loop condition already - or am I overlooking something?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately we still run into the issue , even with the existing loop condition.
check the flowchart of the for loop
https://www.programiz.com/cpp-programming/for-loop
the update condition is done after the body ; then we run into the issue.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, right, I see. But in that case, we can/should remove the check for comma_pos != nullptr from the condition because we're explicitly doing it in the loop body then.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree, the check can be simplified .

}

os::free(copy);
Expand Down