Skip to contentSkip to conversation

cifs-utils: mount.cifs.c/parse_options: const variable is being modified

BUG Rudi Heitbaum 2 participants 2 messages Feb 11 – Feb 17

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

In the mount.cifs.c/parse_options function - data is passed in as const char*.

strchr returns a warning that the const has been discarded since the latest glibc / ISO C22.

code in question is:

https://git.samba.org/?p=cifs-utils.git;a=blob;f=mount.cifs.c;h=192391360bcaa29de964b65f77f0bf93dea64be5;hb=HEAD#l888

889: next_keyword = strchr(data, ','); - returns a const 890: *next_keyword++ = 0; - modifies a const

897: if ((equals = strchr(data, '=')) != NULL) { - returns a const 898: *equals = '\0'; - modifies a const

The warnings are:

../mount.cifs.c: In function 'parse_options':
../mount.cifs.c:889:30: warning: assignment discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers]
889 | next_keyword = strchr(data, ','); /* BB handle sep= */
| ^
../mount.cifs.c:897:29: warning: assignment discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers]
897 | if ((equals = strchr(data, '=')) != NULL) {
| ^

Regards
Rudi

#1 lore raw

I don't see this warning on my Ubuntu test system which seems to be current for glibc

               Ubuntu GLIBC 2.42-0ubuntu3.1) 2.42

Are you using a newer GLIBC? Do you want to submit a patch to fix this (does an explicit cast fix it?)?

By the way, I didn't see your original email since gmail routed it to spam for some reason

Quoted 30 lines · Rudi Heitbaum

In the mount.cifs.c/parse_options function - data is passed in as const char*.

strchr returns a warning that the const has been discarded since the latest glibc / ISO C22.

code in question is:

https://git.samba.org/?p=cifs-utils.git;a=blob;f=mount.cifs.c;h=192391360bcaa29de964b65f77f0bf93dea64be5;hb=HEAD#l888

889: next_keyword = strchr(data, ','); - returns a const 890: *next_keyword++ = 0; - modifies a const

897: if ((equals = strchr(data, '=')) != NULL) { - returns a const 898: *equals = '\0'; - modifies a const

The warnings are:

../mount.cifs.c: In function 'parse_options':
../mount.cifs.c:889:30: warning: assignment discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers]
889 | next_keyword = strchr(data, ','); /* BB handle sep= */
| ^
../mount.cifs.c:897:29: warning: assignment discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers]
897 | if ((equals = strchr(data, '=')) != NULL) {
| ^

Regards
Rudi

Signature · 3 lines
Thanks,

Steve