From: Stefan E. <se...@us...> - 2004-02-05 18:51:54
|
Update of /cvsroot/blob/blob/src/lib In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25457/lib Modified Files: download.c Log Message: Remove strcmp() calls, use strncmp(). Index: download.c =================================================================== RCS file: /cvsroot/blob/blob/src/lib/download.c,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- download.c 4 Dec 2003 21:45:19 -0000 1.4 +++ download.c 5 Feb 2004 18:49:19 -0000 1.5 @@ -52,13 +52,13 @@ { blob_item_t *ret = NULL; - if (!strcmp(what, "blob")) + if (!strncmp(what, "blob", 4)) ret = &blob_status.blob; - else if (!strcmp(what, "param")) + else if (!strncmp(what, "param", 5)) ret = &blob_status.param; - else if (!strcmp(what, "kernel")) + else if (!strncmp(what, "kernel", 6 )) ret = &blob_status.kernel; - else if (!strcmp(what, "ramdisk")) + else if (!strncmp(what, "ramdisk", 7 )) ret = &blob_status.ramdisk; return ret; @@ -128,7 +128,7 @@ #if defined(CONFIG_CRAMFS_SUPPORT) || \ defined(CONFIG_ZIMAGE_SUPPORT) || \ defined(CONFIG_JFFS2_SUPPORT) - if (!strcmp("kernel", what)) { + if (!strncmp("kernel", what, 6 )) { item->size = 0; load_kernel(&blob_status); } else @@ -159,33 +159,33 @@ if(argc < 2) return -ENOPARAMS; - if(strcmp(argv[1], "1200") == 0) { + if(strncmp(argv[1], "1200", 4) == 0) { blob_status.downloadSpeed = baud_1200; - } else if(strcmp(argv[1], "1k2") == 0) { + } else if(strncmp(argv[1], "1k2", 3) == 0) { blob_status.downloadSpeed = baud_1200; - } else if(strcmp(argv[1], "9600") == 0) { + } else if(strncmp(argv[1], "9600", 4) == 0) { blob_status.downloadSpeed = baud_9600; - } else if(strcmp(argv[1], "9k6") == 0) { + } else if(strncmp(argv[1], "9k6", 3) == 0) { blob_status.downloadSpeed = baud_9600; - } else if(strcmp(argv[1], "19200") == 0) { + } else if(strncmp(argv[1], "19200", 5) == 0) { blob_status.downloadSpeed = baud_19200; - } else if(strcmp(argv[1], "19k2") == 0) { + } else if(strncmp(argv[1], "19k2", 4) == 0) { blob_status.downloadSpeed = baud_19200; - } else if(strcmp(argv[1], "38400") == 0) { + } else if(strncmp(argv[1], "38400", 5) == 0) { blob_status.downloadSpeed = baud_38400; - } else if(strcmp(argv[1], "38k4") == 0) { + } else if(strncmp(argv[1], "38k4", 4) == 0) { blob_status.downloadSpeed = baud_38400; - } else if(strcmp(argv[1], "57600") == 0) { + } else if(strncmp(argv[1], "57600", 5) == 0) { blob_status.downloadSpeed = baud_57600; - } else if(strcmp(argv[1], "57k6") == 0) { + } else if(strncmp(argv[1], "57k6", 4) == 0) { blob_status.downloadSpeed = baud_57600; - } else if(strcmp(argv[1], "115200") == 0) { + } else if(strncmp(argv[1], "115200", 6) == 0) { blob_status.downloadSpeed = baud_115200; - } else if(strcmp(argv[1], "115k2") == 0) { + } else if(strncmp(argv[1], "115k2", 5) == 0) { blob_status.downloadSpeed = baud_115200; - } else if(strcmp(argv[1], "230400") == 0) { + } else if(strncmp(argv[1], "230400", 6) == 0) { blob_status.downloadSpeed = baud_230400; - } else if(strcmp(argv[1], "230k4") == 0) { + } else if(strncmp(argv[1], "230k4", 5) == 0) { blob_status.downloadSpeed = baud_230400; } else { return -EINVAL; |
From: Russ D. <Rus...@as...> - 2004-02-05 22:16:06
|
On Thu, 2004-02-05 at 11:49, Stefan Eletzhofer wrote: > Update of /cvsroot/blob/blob/src/lib > In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25457/lib > > Modified Files: > download.c > Log Message: > Remove strcmp() calls, use strncmp(). the strncmp calls were removed on purpose. Making you sit there and count the characters is error prone. strcmp in blob is just a macro: #define strcmp(s1, s2) \ (__builtin_constant_p(s1) ? strncmp(s1, s2, sizeof(s1)) : \ (__builtin_constant_p(s2) ? strncmp(s1, s2, sizeof(s2)) : \ unsafe_strcmp_call(s1, s2))) If one of the arguments is not a constant, then it will cause a link error. Otherwise, it will count the number of characters for you, and replace the call with strncmp -- Russ Dill <Rus...@as...> |
From: <ste...@el...> - 2004-02-06 10:07:29
|
On Thu, Feb 05, 2004 at 03:16:21PM -0700, Russ Dill wrote: > On Thu, 2004-02-05 at 11:49, Stefan Eletzhofer wrote: > > Update of /cvsroot/blob/blob/src/lib > > In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25457/lib > > > > Modified Files: > > download.c > > Log Message: > > Remove strcmp() calls, use strncmp(). > > the strncmp calls were removed on purpose. Making you sit there and > count the characters is error prone. strcmp in blob is just a macro: > > #define strcmp(s1, s2) \ > (__builtin_constant_p(s1) ? strncmp(s1, s2, sizeof(s1)) : \ > (__builtin_constant_p(s2) ? strncmp(s1, s2, sizeof(s2)) : \ > unsafe_strcmp_call(s1, s2))) But I got link errors. The above macro ended up un a call to unsave_strcmp_call(). Thats why I noticed, and thus converted the whole mess. I didnt notice this macro, I thought erik removed strcmp() altogether. (This was gcc 2.95.3) > > If one of the arguments is not a constant, then it will cause a link error. > Otherwise, it will count the number of characters for you, and replace the > call with strncmp > > -- > Russ Dill <Rus...@as...> -- Eletztrick Computing - Customized Linux Development Stefan Eletzhofer, Marktstrasse 43, DE-88214 Ravensburg http://www.eletztrick.de |
From: Russ D. <Rus...@as...> - 2004-02-06 10:29:46
|
> But I got link errors. The above macro ended up un a call to unsave_strcmp_call(). Thats > why I noticed, and thus converted the whole mess. I didnt notice this macro, I thought erik > removed strcmp() altogether. > > (This was gcc 2.95.3) > If you get link errors, then I need to fix the macro. Any clue why gcc 2.95.3 isn't return true on __builtin_constant_p("blob")? -- Russ Dill <Rus...@as...> |