Skip to contentSkip to conversation

Switch legacy index() in favour of strchr()

PATCH In review Petr Vorel 2 participants 3 messages Nov 22, 2019

Subsystems (2)
lore
Share & tools
lore

Petr Vorel

author
#0 lore raw

PATCH 1/1 Switch legacy index() in favour of strchr()

From: Frederik Pasch <[email protected]>

[ gustavo: rebased to 1.2.6 ]
[ pvorel: taken from Buildroot distribution, rebased ]
---
 support/nfs/nfs_mntent.c | 6 +++---
 utils/mount/error.c      | 2 +-
 utils/mountd/fsloc.c     | 2 +-
 3 files changed, 5 insertions(+), 5 deletions(-)
support/nfs/nfs_mntent.c +3 -3
index 05a4c687..25e5944a 100644
@@ -9,7 +9,7 @@
  */
 
 #include <stdio.h>
-#include <string.h>		/* for index */
+#include <string.h>		/* for strchr */
 #include <ctype.h>		/* for isdigit */
 #include <sys/stat.h>		/* for umask */
 #include <unistd.h>		/* for ftruncate */
@@ -176,7 +176,7 @@ nfs_getmntent (mntFILE *mfp) {
 			return NULL;
 
 		mfp->mntent_lineno++;
-		s = index (buf, '\n');
+		s = strchr (buf, '\n');
 		if (s == NULL) {
 			/* Missing final newline?  Otherwise extremely */
 			/* long line - assume file was corrupted */
@@ -184,7 +184,7 @@ nfs_getmntent (mntFILE *mfp) {
 				fprintf(stderr, _("[mntent]: warning: no final "
 					"newline at the end of %s\n"),
 					mfp->mntent_file);
-				s = index (buf, 0);
+				s = strchr (buf, 0);
 			} else {
 				mfp->mntent_errs = 1;
 				goto err;
utils/mount/error.c +1 -1
index 562f312e..986f0660 100644
@@ -62,7 +62,7 @@ static int rpc_strerror(int spos)
 	char *tmp;
 
 	if (estr) {
-		if ((ptr = index(estr, ':')))
+		if ((ptr = strchr(estr, ':')))
 			estr = ++ptr;
 
 		tmp = &errbuf[spos];
utils/mountd/fsloc.c +1 -1
index cf42944f..1b869b60 100644
@@ -128,7 +128,7 @@ static struct servers *method_list(char *data)
 	bool v6esc = false;
 
 	xlog(L_NOTICE, "method_list(%s)", data);
-	for (ptr--, listsize=1; ptr; ptr=index(ptr, ':'), listsize++)
+	for (ptr--, listsize=1; ptr; ptr=strchr(ptr, ':'), listsize++)
 		ptr++;
 	list = malloc(listsize * sizeof(char *));
 	copy = strdup(data);
Signature · 1 line
2.24.0
author
#1 lore raw

Hi Steve,

Quoted 1 line

From: Frederik Pasch <[email protected]>

NOTE: this fixes build on musl, which has index() only in legacy <strings.h> (not in <string.h> unlike glibc/uclibc).

Kind regards,
Petr

#2 lore raw
In reply to Petr Vorel
Quoted 8 lines · Petr Vorel

From: Frederik Pasch <[email protected]>

[ gustavo: rebased to 1.2.6 ]
[ pvorel: taken from Buildroot distribution, rebased ]
Quoted 5 lines
---
 support/nfs/nfs_mntent.c | 6 +++---
 utils/mount/error.c      | 2 +-
 utils/mountd/fsloc.c     | 2 +-
 3 files changed, 5 insertions(+), 5 deletions(-)

Committed... (tag: nfs-utils-2-4-3-rc2)

steved.

Quoted 59 lines
support/nfs/nfs_mntent.c +3 -3
index 05a4c687..25e5944a 100644
@@ -9,7 +9,7 @@
  */
 
 #include <stdio.h>
-#include <string.h>		/* for index */
+#include <string.h>		/* for strchr */
 #include <ctype.h>		/* for isdigit */
 #include <sys/stat.h>		/* for umask */
 #include <unistd.h>		/* for ftruncate */
@@ -176,7 +176,7 @@ nfs_getmntent (mntFILE *mfp) {
 			return NULL;
 
 		mfp->mntent_lineno++;
-		s = index (buf, '\n');
+		s = strchr (buf, '\n');
 		if (s == NULL) {
 			/* Missing final newline?  Otherwise extremely */
 			/* long line - assume file was corrupted */
@@ -184,7 +184,7 @@ nfs_getmntent (mntFILE *mfp) {
 				fprintf(stderr, _("[mntent]: warning: no final "
 					"newline at the end of %s\n"),
 					mfp->mntent_file);
-				s = index (buf, 0);
+				s = strchr (buf, 0);
 			} else {
 				mfp->mntent_errs = 1;
 				goto err;
utils/mount/error.c +1 -1
index 562f312e..986f0660 100644
@@ -62,7 +62,7 @@ static int rpc_strerror(int spos)
 	char *tmp;
 
 	if (estr) {
-		if ((ptr = index(estr, ':')))
+		if ((ptr = strchr(estr, ':')))
 			estr = ++ptr;
 
 		tmp = &errbuf[spos];
utils/mountd/fsloc.c +1 -1
index cf42944f..1b869b60 100644
@@ -128,7 +128,7 @@ static struct servers *method_list(char *data)
 	bool v6esc = false;
 
 	xlog(L_NOTICE, "method_list(%s)", data);
-	for (ptr--, listsize=1; ptr; ptr=index(ptr, ':'), listsize++)
+	for (ptr--, listsize=1; ptr; ptr=strchr(ptr, ':'), listsize++)
 		ptr++;
 	list = malloc(listsize * sizeof(char *));
 	copy = strdup(data);