Skip to content

Commit 736bb11

Browse files
goldelicomasahir0y
authored andcommitted
modpost: remove use of non-standard strsep() in HOSTCC code
strsep() is neither standard C nor POSIX and used outside the kernel code here. Using it here requires that the build host supports it out of the box which is e.g. not true for a Darwin build host and using a cross-compiler. This leads to: scripts/mod/modpost.c:145:2: warning: implicit declaration of function 'strsep' [-Wimplicit-function-declaration] return strsep(stringp, "\n"); ^ and a segfault when running MODPOST. See also: https://stackoverflow.com/a/7219504 So let's replace this by strchr() instead of using strsep(). It does not hurt kernel size or speed since this code is run on the build host. Fixes: ac5100f ("modpost: add read_text_file() and get_line() helpers") Co-developed-by: Masahiro Yamada <[email protected]> Signed-off-by: H. Nikolaus Schaller <[email protected]> Signed-off-by: Masahiro Yamada <[email protected]>
1 parent dcb7fd8 commit 736bb11

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

scripts/mod/modpost.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,11 +138,19 @@ char *read_text_file(const char *filename)
138138

139139
char *get_line(char **stringp)
140140
{
141+
char *orig = *stringp, *next;
142+
141143
/* do not return the unwanted extra line at EOF */
142-
if (*stringp && **stringp == '\0')
144+
if (!orig || *orig == '\0')
143145
return NULL;
144146

145-
return strsep(stringp, "\n");
147+
next = strchr(orig, '\n');
148+
if (next)
149+
*next++ = '\0';
150+
151+
*stringp = next;
152+
153+
return orig;
146154
}
147155

148156
/* A list of all modules we processed */

0 commit comments

Comments
 (0)