Skip to content

Commit bc81e68

Browse files
committed
Remove discard qualifiers warning with C23 strchr
C23 has qualifier-preserving standard library functions, so calling strchr with a `const char *` will return a `const char *`. We can change the type of the local variables because we don't mutate the strings.
1 parent 36a22e0 commit bc81e68

3 files changed

Lines changed: 4 additions & 4 deletions

File tree

hash.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6487,7 +6487,7 @@ env_rassoc(VALUE dmy, VALUE obj)
64876487

64886488
while (*env) {
64896489
const char *p = *env;
6490-
char *s = strchr(p, '=');
6490+
const char *s = strchr(p, '=');
64916491
if (s++) {
64926492
long len = strlen(s);
64936493
if (RSTRING_LEN(obj) == len && strncmp(s, RSTRING_PTR(obj), len) == 0) {
@@ -6707,7 +6707,7 @@ env_shift(VALUE _)
67076707
char **env = GET_ENVIRON(environ);
67086708
if (*env) {
67096709
const char *p = *env;
6710-
char *s = strchr(p, '=');
6710+
const char *s = strchr(p, '=');
67116711
if (s) {
67126712
key = env_str_new(p, s-p, enc);
67136713
VALUE val = env_str_new2(getenv(RSTRING_PTR(key)), enc);

load.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1712,7 +1712,7 @@ rb_ext_resolve_symbol(const char* fname, const char* symbol)
17121712
VALUE handle;
17131713
VALUE resolved;
17141714
VALUE path;
1715-
char *ext;
1715+
const char *ext;
17161716
VALUE fname_str = rb_str_new_cstr(fname);
17171717
const rb_box_t *box = rb_loading_box();
17181718

ruby.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1373,7 +1373,7 @@ proc_0_option(ruby_cmdline_options_t *opt, const char *s)
13731373
static void
13741374
proc_encoding_option(ruby_cmdline_options_t *opt, const char *s, const char *opt_name)
13751375
{
1376-
char *p;
1376+
const char *p;
13771377
# define set_encoding_part(type) \
13781378
if (!(p = strchr(s, ':'))) { \
13791379
set_##type##_encoding_once(opt, s, 0); \

0 commit comments

Comments
 (0)