liblsd: fix const-correctness in _parse_single_range() - #216
Merged
Merged
Conversation
Member
|
Good catch! However, a bunch of CI tests are failing with this change, for example: Ah, this seems to be required on top of your change @@ -1423,8 +1423,8 @@ static int _parse_single_range(const char *str, struct _range *range)
seterrno_ret(ERANGE, 0);
}
+ range->width = strlen(orig);
free(orig);
- range->width = strlen(str);
return 1;
error: |
Member
Member
|
@hector-cao - let me know if you have time to amend and force push this commit with the proposed addition. If not I can submit a new PR. Thanks. |
_parse_single_range() accepts a `const char *str` argument and creates a mutable copy via strdup() into `orig`. However, it was incorrectly calling strchr() and strtoul() on the original const pointer `str` rather than on the mutable copy. This is both a correctness bug and a build failure with modern glibc: - glibc now provides const-preserving overloads of strchr(), returning `const char *` when passed a `const char *`. Assigning this to `char *p` discards the const qualifier, triggering a compile error with -Werror=discarded-qualifiers. - The subsequent `*p++ = '\0'` write through `p` would modify memory via a pointer originally derived from a const string. Fix by using `orig` (the mutable strdup copy) for strchr() and strtoul() calls, which is the correct buffer to mutate.
hector-cao
force-pushed
the
fix-const-ness
branch
from
May 29, 2026 13:44
6a5cb7b to
3495907
Compare
Contributor
Author
thanks for this speedy feedback, updated |
Member
|
Looking good here so let's merge. Thank you for running this down and for your excellent commit message! Let's merge. |
erentar
added a commit
to erentar/diod
that referenced
this pull request
Jun 23, 2026
This fix was authored by hector-cao originally for chaos/powerman#216. _parse_single_range() accepts a `const char *str` argument and creates a mutable copy via strdup() into `orig`. However, it was incorrectly calling strchr() and strtoul() on the original const pointer `str` rather than on the mutable copy. This is both a correctness bug and a build failure with modern glibc: - glibc now provides const-preserving overloads of strchr(), returning `const char *` when passed a `const char *`. Assigning this to `char *p` discards the const qualifier, triggering a compile error with -Werror=discarded-qualifiers. - The subsequent `*p++ = '\0'` write through `p` would modify memory via a pointer originally derived from a const string. Fix by using `orig` (the mutable strdup copy) for strchr() and strtoul() calls, which is the correct buffer to mutate.
erentar
added a commit
to erentar/diod
that referenced
this pull request
Jun 23, 2026
This fix was authored by hector-cao originally for chaos/powerman#216. _parse_single_range() accepts a `const char *str` argument and creates a mutable copy via strdup() into `orig`. However, it was incorrectly calling strchr() and strtoul() on the original const pointer `str` rather than on the mutable copy. This is both a correctness bug and a build failure with modern glibc: - glibc now provides const-preserving overloads of strchr(), returning `const char *` when passed a `const char *`. Assigning this to `char *p` discards the const qualifier, triggering a compile error with -Werror=discarded-qualifiers. - The subsequent `*p++ = '\0'` write through `p` would modify memory via a pointer originally derived from a const string. Fix by using `orig` (the mutable strdup copy) for strchr() and strtoul() calls, which is the correct buffer to mutate.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
_parse_single_range() accepts a
const char *strargument and creates a mutable copy via strdup() intoorig. However, it was incorrectly calling strchr() and strtoul() on the original const pointerstrrather than on the mutable copy.This is both a correctness bug and a build failure with modern glibc:
const char *when passed aconst char *. Assigning this tochar *pdiscards the const qualifier, triggering a compile error with -Werror=discarded-qualifiers.*p++ = '\0'write throughpwould modify memory via a pointer originally derived from a const string.Fix by using
orig(the mutable strdup copy) for strchr() and strtoul() calls, which is the correct buffer to mutate.