Skip to content

Commit ac9e351

Browse files
committed
cleanup: Use memcmp instead of strncmp for size same as constant string
1 parent d277db9 commit ac9e351

41 files changed

Lines changed: 102 additions & 99 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

ee/font/src/fontx.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ int fontx_load(const char *path, fontx_t* fontx, int type, int wmargin, int hmar
331331

332332
fontx_header = (fontx_hdr*)fontx->font;
333333

334-
if (strncmp(fontx_header->id, "FONTX2", 6) != 0)
334+
if (memcmp(fontx_header->id, "FONTX2", 6) != 0)
335335
{
336336

337337
printf("Not FONTX2 type font!\n");

ee/libcglue/samples/regress/stdio_tests.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ static const char *test_fseek_ftell(void *arg)
133133
}
134134

135135
ret = fread(buf, 2, 1, fp);
136-
if (ret != 1 || strncmp(buf, "he", 2) != 0)
136+
if (ret != 1 || memcmp(buf, "he", 2) != 0)
137137
{
138138
error = "failed to read first two bytes";
139139
goto failed;
@@ -149,7 +149,7 @@ static const char *test_fseek_ftell(void *arg)
149149
}
150150

151151
ret = fread(buf, 2, 1, fp);
152-
if (ret != 1 || strncmp(buf, "o ", 2) != 0)
152+
if (ret != 1 || memcmp(buf, "o ", 2) != 0)
153153
{
154154
error = "error reading from test file";
155155
goto failed;
@@ -165,7 +165,7 @@ static const char *test_fseek_ftell(void *arg)
165165
}
166166

167167
ret = fread(buf, 2, 1, fp);
168-
if (ret != 1 || strncmp(buf, "o ", 2) != 0)
168+
if (ret != 1 || memcmp(buf, "o ", 2) != 0)
169169
{
170170
error = "error reading from test file";
171171
goto failed;
@@ -203,23 +203,23 @@ static const char *test_fread(void *arg)
203203

204204
/* test of reading one chunk */
205205
ret = fread(buf, 3, 1, fp);
206-
if (ret != 1 || strncmp(buf, "hel", 3) != 0)
206+
if (ret != 1 || memcmp(buf, "hel", 3) != 0)
207207
{
208208
error = "failed to read one block";
209209
goto failed;
210210
}
211211

212212
/* three chunks */
213213
ret = fread(buf, 2, 3, fp);
214-
if (ret != 3 || strncmp(buf, "lo wor", 6) != 0)
214+
if (ret != 3 || memcmp(buf, "lo wor", 6) != 0)
215215
{
216216
error = "failed to read three blocks";
217217
goto failed;
218218
}
219219

220220
/* until end of file */
221221
ret = fread(buf, 1, sizeof(buf), fp);
222-
if (ret < 2 || strncmp(buf, "ld", 2) != 0)
222+
if (ret < 2 || memcmp(buf, "ld", 2) != 0)
223223
{
224224
error = "failed to read until eof";
225225
goto failed;
@@ -265,7 +265,7 @@ static const char *test_fwrite(void *arg)
265265

266266
fseek(fp, 0, SEEK_SET);
267267
ret = fread(buf2, 2, 1, fp);
268-
if (ret != 1 || strncmp(buf2, "he", 2) != 0)
268+
if (ret != 1 || memcmp(buf2, "he", 2) != 0)
269269
{
270270
fclose(fp);
271271
printf("buf2 = %s ret = %d\n", buf2, ret);
@@ -281,7 +281,7 @@ static const char *test_fwrite(void *arg)
281281

282282
fseek(fp, 0, SEEK_SET);
283283
ret = fread(buf2, 1, sizeof(buf2), fp);
284-
if (ret != 13 || strncmp(buf2, "hehello world", 13))
284+
if (ret != 13 || memcmp(buf2, "hehello world", 13))
285285
{
286286
fclose(fp);
287287
return "failed to write rest of file";

ee/libcglue/src/ps2sdkapi.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,7 @@ int __fioGetstatHelper(const char *path, struct stat *buf)
423423
{
424424
io_stat_t fiostat;
425425

426-
if (strncmp(path, "tty", 3) == 0 && path[3] >= '0' && path[3] <= '9' && path[4] == ':')
426+
if (memcmp(path, "tty", 3) == 0 && path[3] >= '0' && path[3] <= '9' && path[4] == ':')
427427
{
428428
memset(buf, 0, sizeof(*buf));
429429
buf->st_mode = S_IFCHR;

ee/rpc/filexio/src/fileXio_ps2sdk.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ static void fill_stat(struct stat *stat, const iox_stat_t *fiostat)
193193
int __fileXioGetstatHelper(const char *path, struct stat *buf) {
194194
iox_stat_t fiostat;
195195

196-
if (strncmp(path, "tty", 3) == 0 && path[3] >= '0' && path[3] <= '9' && path[4] == ':')
196+
if (memcmp(path, "tty", 3) == 0 && path[3] >= '0' && path[3] <= '9' && path[4] == ':')
197197
{
198198
memset(buf, 0, sizeof(*buf));
199199
buf->st_mode = S_IFCHR;

ee/rpc/multitap/samples/mtap_sample.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ int main(int argc, char *argv[])
205205

206206
printf("libmtap sample");
207207

208-
if((argc == 2) && (strncmp(argv[1], "free", 4) == 0))
208+
if((argc == 2) && (memcmp(argv[1], "free", 4) == 0))
209209
{
210210
printf(" - Using PS2SDK sio2man.irx, mtapman.irx and padman.irx modules.\n");
211211
loadmodules(1);

ee/rpc/pad/samples/padx/padx.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ int main(int argc, char *argv[])
105105

106106
printf("libpadx sample");
107107

108-
if((argc == 2) && (strncmp(argv[1], "free", 4) == 0))
108+
if((argc == 2) && (memcmp(argv[1], "free", 4) == 0))
109109
{
110110
printf(" - Using PS2SDK sio2man.irx and padman.irx modules.\n");
111111
loadmodules(1);

ee/rpc/remote/samples/remote.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ int main(int argc, char *argv[])
271271
scr_printf("Loading modules...\n");
272272

273273
/* Load modules */
274-
if ((argc == 2) && (strncmp(argv[1], "free", 4) == 0))
274+
if ((argc == 2) && (memcmp(argv[1], "free", 4) == 0))
275275
{
276276
scr_printf(" - Using PS2SDK sio2man.irx, rmman.irx modules.\n");
277277
loadmodules(1);

iop/arcade/accdvd/src/cdfs.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ static int cdfs_attach(struct cdfs_softc *cdfsc, struct acd *acd, int remount)
172172
printf("cdfs:super:read: error %d\n", active_v12);
173173
break;
174174
}
175-
if ( !strncmp((const char *)buf + 1, "CD001", 5u) )
175+
if ( !memcmp((const char *)buf + 1, "CD001", 5u) )
176176
{
177177
int active_v13;
178178

iop/arcade/accdvd/src/imports.lst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ sysclib_IMPORTS_start
3939
I_memcpy
4040
I_memset
4141
I_strlen
42-
I_strncmp
42+
I_memcmp
4343
sysclib_IMPORTS_end
4444

4545
thbase_IMPORTS_start

iop/arcade/romwrite/src/imports.lst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ I_sprintf
4343
I_strcat
4444
I_strcmp
4545
I_strcpy
46-
I_strncmp
46+
I_memcmp
4747
I_strncpy
4848
I_strtol
4949
I_vsprintf

0 commit comments

Comments
 (0)