Skip to contentSkip to conversation

nfs-utils: mount.nfs: fix discards const from pointer target

PATCH In review Rudi Heitbaum 2 participants 2 messages Feb 15 – Feb 24

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

PATCH 1/2 nfs-utils: mount.nfs: fix discards const from pointer target

dev is passed by nfs_parse_devname to nfs_parse_... as a copy of the device name, the parser destructively modifies dev, so pass as non const so that it can be modified without warning.

fixes:
parse_dev.c: In function 'nfs_parse_simple_hostname':
parse_dev.c:89:15: warning: assignment discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers]
89 | colon = strchr(dev, ':');
| ^
parse_dev.c:100:15: warning: assignment discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers]
100 | comma = strchr(dev, ',');
| ^
parse_dev.c: In function 'nfs_parse_square_bracket':
parse_dev.c:146:16: warning: assignment discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers]
146 | cbrace = strchr(dev, ']');
| ^

---
 utils/mount/parse_dev.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
utils/mount/parse_dev.c +3 -3
index 2ade5d5d..a6354bba 100644
@@ -79,7 +79,7 @@ static int nfs_pdn_missing_brace_err(void)
 /*
  * Standard hostname:path format
  */
-static int nfs_parse_simple_hostname(const char *dev,
+static int nfs_parse_simple_hostname(char *dev,
 				     char **hostname, char **pathname)
 {
 	size_t host_len, path_len;
@@ -134,7 +134,7 @@ static int nfs_parse_simple_hostname(const char *dev,
  * There could be anything in between the brackets, but we'll
  * let DNS resolution sort it out later.
  */
-static int nfs_parse_square_bracket(const char *dev,
+static int nfs_parse_square_bracket(char *dev,
 				    char **hostname, char **pathname)
 {
 	size_t host_len, path_len;
@@ -185,7 +185,7 @@ static int nfs_parse_square_bracket(const char *dev,
  * with the mount request and failing with a cryptic error message
  * later.
  */
-static int nfs_parse_nfs_url(__attribute__((unused)) const char *dev,
+static int nfs_parse_nfs_url(__attribute__((unused)) char *dev,
 			     __attribute__((unused)) char **hostname,
 			     __attribute__((unused)) char **pathname)
 {
Signature · 1 line
2.51.0
#1 lore raw
Quoted 17 lines · Rudi Heitbaum

dev is passed by nfs_parse_devname to nfs_parse_... as a copy of the device name, the parser destructively modifies dev, so pass as non const so that it can be modified without warning.

fixes:
parse_dev.c: In function 'nfs_parse_simple_hostname':
parse_dev.c:89:15: warning: assignment discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers]
89 | colon = strchr(dev, ':');
| ^
parse_dev.c:100:15: warning: assignment discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers]
100 | comma = strchr(dev, ',');
| ^
parse_dev.c: In function 'nfs_parse_square_bracket':
parse_dev.c:146:16: warning: assignment discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers]
146 | cbrace = strchr(dev, ']');
| ^

Quoted 1 line

Committed... (tag: nfs-utils-2-8-6-rc2)

steved.

Quoted 35 lines
---
  utils/mount/parse_dev.c | 6 +++---
  1 file changed, 3 insertions(+), 3 deletions(-)
utils/mount/parse_dev.c +3 -3
index 2ade5d5d..a6354bba 100644
@@ -79,7 +79,7 @@ static int nfs_pdn_missing_brace_err(void)
  /*
   * Standard hostname:path format
   */
-static int nfs_parse_simple_hostname(const char *dev,
+static int nfs_parse_simple_hostname(char *dev,
  				     char **hostname, char **pathname)
  {
  	size_t host_len, path_len;
@@ -134,7 +134,7 @@ static int nfs_parse_simple_hostname(const char *dev,
   * There could be anything in between the brackets, but we'll
   * let DNS resolution sort it out later.
   */
-static int nfs_parse_square_bracket(const char *dev,
+static int nfs_parse_square_bracket(char *dev,
  				    char **hostname, char **pathname)
  {
  	size_t host_len, path_len;
@@ -185,7 +185,7 @@ static int nfs_parse_square_bracket(const char *dev,
   * with the mount request and failing with a cryptic error message
   * later.
   */
-static int nfs_parse_nfs_url(__attribute__((unused)) const char *dev,
+static int nfs_parse_nfs_url(__attribute__((unused)) char *dev,
  			     __attribute__((unused)) char **hostname,
  			     __attribute__((unused)) char **pathname)
  {