aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2009-09-23 17:17:53 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2009-09-23 17:17:53 +0200
commit1f27ab0d4bb65425496ff4ed0fbbd0f5bb32786f (patch)
treea7181ba3c498570257040c8663f125938ecad0a6
parent8d338173a4668740b1ab4a40d1d26cd25402e406 (diff)
downloadbusybox-w32-1f27ab0d4bb65425496ff4ed0fbbd0f5bb32786f.tar.gz
busybox-w32-1f27ab0d4bb65425496ff4ed0fbbd0f5bb32786f.tar.bz2
busybox-w32-1f27ab0d4bb65425496ff4ed0fbbd0f5bb32786f.zip
*: optimize code size in strtoul calls
function old new delta bb_parse_mode 433 431 -2 rtnl_rtntype_a2n 202 198 -4 ParseField 511 498 -13 bb_init_module_24 4730 4675 -55 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 0/4 up/down: 0/-74) Total: -74 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--libbb/parse_mode.c2
-rw-r--r--libpwdgrp/pwd_grp.c18
-rw-r--r--miscutils/crond.c10
-rw-r--r--modutils/modutils-24.c18
-rw-r--r--networking/libiproute/rtm_map.c2
-rw-r--r--networking/libiproute/utils.c3
-rw-r--r--networking/tc.c5
-rw-r--r--shell/ash.c2
8 files changed, 37 insertions, 23 deletions
diff --git a/libbb/parse_mode.c b/libbb/parse_mode.c
index 40105dd3a..6eca00ab1 100644
--- a/libbb/parse_mode.c
+++ b/libbb/parse_mode.c
@@ -40,7 +40,7 @@ int FAST_FUNC bb_parse_mode(const char *s, mode_t *current_mode)
40 mode_t new_mode; 40 mode_t new_mode;
41 char op; 41 char op;
42 42
43 if (((unsigned int)(*s - '0')) < 8) { 43 if ((unsigned char)(*s - '0') < 8) {
44 unsigned long tmp; 44 unsigned long tmp;
45 char *e; 45 char *e;
46 46
diff --git a/libpwdgrp/pwd_grp.c b/libpwdgrp/pwd_grp.c
index e2077ade0..947f48d43 100644
--- a/libpwdgrp/pwd_grp.c
+++ b/libpwdgrp/pwd_grp.c
@@ -816,7 +816,7 @@ static int bb__parsepwent(void *data, char *line)
816 816
817 i = 0; 817 i = 0;
818 do { 818 do {
819 p = ((char *) ((struct passwd *) data)) + pw_off[i]; 819 p = (char *) data + pw_off[i];
820 820
821 if ((i & 6) ^ 2) { /* i!=2 and i!=3 */ 821 if ((i & 6) ^ 2) { /* i!=2 and i!=3 */
822 *((char **) p) = line; 822 *((char **) p) = line;
@@ -873,7 +873,7 @@ static int bb__parsegrent(void *data, char *line)
873 end_of_buf = ((struct group *) data)->gr_name; /* Evil hack! */ 873 end_of_buf = ((struct group *) data)->gr_name; /* Evil hack! */
874 i = 0; 874 i = 0;
875 do { 875 do {
876 p = ((char *) ((struct group *) data)) + gr_off[i]; 876 p = (char *) data + gr_off[i];
877 877
878 if (i < 2) { 878 if (i < 2) {
879 *((char **) p) = line; 879 *((char **) p) = line;
@@ -966,15 +966,15 @@ static const unsigned char sp_off[] ALIGN1 = {
966 offsetof(struct spwd, sp_flag) /* 8 - not a char ptr */ 966 offsetof(struct spwd, sp_flag) /* 8 - not a char ptr */
967}; 967};
968 968
969static int bb__parsespent(void *data, char * line) 969static int bb__parsespent(void *data, char *line)
970{ 970{
971 char *endptr; 971 char *endptr;
972 char *p; 972 char *p;
973 int i; 973 int i;
974 974
975 i = 0; 975 i = 0;
976 do { 976 while (1) {
977 p = ((char *) ((struct spwd *) data)) + sp_off[i]; 977 p = (char *) data + sp_off[i];
978 if (i < 2) { 978 if (i < 2) {
979 *((char **) p) = line; 979 *((char **) p) = line;
980 line = strchr(line, ':'); 980 line = strchr(line, ':');
@@ -982,10 +982,10 @@ static int bb__parsespent(void *data, char * line)
982 break; 982 break;
983 } 983 }
984 } else { 984 } else {
985 *((long *) p) = (long) strtoul(line, &endptr, 10); 985 *((long *) p) = strtoul(line, &endptr, 10);
986 986
987 if (endptr == line) { 987 if (endptr == line) {
988 *((long *) p) = ((i != 8) ? -1L : ((long)(~0UL))); 988 *((long *) p) = (i != 8) ? -1L : (long)(~0UL);
989 } 989 }
990 990
991 line = endptr; 991 line = endptr;
@@ -1003,9 +1003,9 @@ static int bb__parsespent(void *data, char * line)
1003 1003
1004 } 1004 }
1005 1005
1006 *line++ = 0; 1006 *line++ = '\0';
1007 ++i; 1007 ++i;
1008 } while (1); 1008 }
1009 1009
1010 return EINVAL; 1010 return EINVAL;
1011} 1011}
diff --git a/miscutils/crond.c b/miscutils/crond.c
index f0b64fe3a..d2104c36f 100644
--- a/miscutils/crond.c
+++ b/miscutils/crond.c
@@ -320,11 +320,13 @@ static void ParseField(char *user, char *ary, int modvalue, int off,
320 skip = 1; 320 skip = 1;
321 ++ptr; 321 ++ptr;
322 } else if (isdigit(*ptr)) { 322 } else if (isdigit(*ptr)) {
323 char *endp;
323 if (n1 < 0) { 324 if (n1 < 0) {
324 n1 = strtol(ptr, &ptr, 10) + off; 325 n1 = strtol(ptr, &endp, 10) + off;
325 } else { 326 } else {
326 n2 = strtol(ptr, &ptr, 10) + off; 327 n2 = strtol(ptr, &endp, 10) + off;
327 } 328 }
329 ptr = endp; /* gcc likes temp var for &endp */
328 skip = 1; 330 skip = 1;
329 } else if (names) { 331 } else if (names) {
330 int i; 332 int i;
@@ -361,7 +363,9 @@ static void ParseField(char *user, char *ary, int modvalue, int off,
361 n2 = n1; 363 n2 = n1;
362 } 364 }
363 if (*ptr == '/') { 365 if (*ptr == '/') {
364 skip = strtol(ptr + 1, &ptr, 10); 366 char *endp;
367 skip = strtol(ptr + 1, &endp, 10);
368 ptr = endp; /* gcc likes temp var for &endp */
365 } 369 }
366 370
367 /* 371 /*
diff --git a/modutils/modutils-24.c b/modutils/modutils-24.c
index 9f91c9979..e5ff54d29 100644
--- a/modutils/modutils-24.c
+++ b/modutils/modutils-24.c
@@ -2432,11 +2432,11 @@ new_process_module_arguments(struct obj_file *f, const char *options)
2432 loc = contents + sym->value; 2432 loc = contents + sym->value;
2433 2433
2434 if (*pinfo == 'c') { 2434 if (*pinfo == 'c') {
2435 if (!isdigit(*(pinfo + 1))) { 2435 if (!isdigit(pinfo[1])) {
2436 bb_error_msg_and_die("parameter type 'c' for %s must be followed by" 2436 bb_error_msg_and_die("parameter type 'c' for %s must be followed by"
2437 " the maximum size", param); 2437 " the maximum size", param);
2438 } 2438 }
2439 charssize = strtoul(pinfo + 1, (char **) NULL, 10); 2439 charssize = strtoul(pinfo + 1, NULL, 10);
2440 } 2440 }
2441 2441
2442 if (val == NULL) { 2442 if (val == NULL) {
@@ -2449,6 +2449,8 @@ new_process_module_arguments(struct obj_file *f, const char *options)
2449 n = 0; 2449 n = 0;
2450 p = val; 2450 p = val;
2451 while (*p != 0) { 2451 while (*p != 0) {
2452 char *endp;
2453
2452 if (++n > max) 2454 if (++n > max)
2453 bb_error_msg_and_die("too many values for %s (max %d)", param, max); 2455 bb_error_msg_and_die("too many values for %s (max %d)", param, max);
2454 2456
@@ -2472,19 +2474,23 @@ new_process_module_arguments(struct obj_file *f, const char *options)
2472 p += len; 2474 p += len;
2473 break; 2475 break;
2474 case 'b': 2476 case 'b':
2475 *loc++ = strtoul(p, &p, 0); 2477 *loc++ = strtoul(p, &endp, 0);
2478 p = endp; /* gcc likes temp var for &endp */
2476 break; 2479 break;
2477 case 'h': 2480 case 'h':
2478 *(short *) loc = strtoul(p, &p, 0); 2481 *(short *) loc = strtoul(p, &endp, 0);
2479 loc += tgt_sizeof_short; 2482 loc += tgt_sizeof_short;
2483 p = endp;
2480 break; 2484 break;
2481 case 'i': 2485 case 'i':
2482 *(int *) loc = strtoul(p, &p, 0); 2486 *(int *) loc = strtoul(p, &endp, 0);
2483 loc += tgt_sizeof_int; 2487 loc += tgt_sizeof_int;
2488 p = endp;
2484 break; 2489 break;
2485 case 'l': 2490 case 'l':
2486 *(long *) loc = strtoul(p, &p, 0); 2491 *(long *) loc = strtoul(p, &endp, 0);
2487 loc += tgt_sizeof_long; 2492 loc += tgt_sizeof_long;
2493 p = endp;
2488 break; 2494 break;
2489 default: 2495 default:
2490 bb_error_msg_and_die("unknown parameter type '%c' for %s", 2496 bb_error_msg_and_die("unknown parameter type '%c' for %s",
diff --git a/networking/libiproute/rtm_map.c b/networking/libiproute/rtm_map.c
index ca2f4436a..6fe5c4b75 100644
--- a/networking/libiproute/rtm_map.c
+++ b/networking/libiproute/rtm_map.c
@@ -88,7 +88,7 @@ int rtnl_rtntype_a2n(int *id, char *arg)
88 res = RTN_THROW; 88 res = RTN_THROW;
89 else { 89 else {
90 res = strtoul(arg, &end, 0); 90 res = strtoul(arg, &end, 0);
91 if (!end || end == arg || *end || res > 255) 91 if (end == arg || *end || res > 255)
92 return -1; 92 return -1;
93 } 93 }
94 *id = res; 94 *id = res;
diff --git a/networking/libiproute/utils.c b/networking/libiproute/utils.c
index c84d018eb..5f0971751 100644
--- a/networking/libiproute/utils.c
+++ b/networking/libiproute/utils.c
@@ -22,6 +22,7 @@ unsigned get_unsigned(char *arg, const char *errmsg)
22 22
23 if (*arg) { 23 if (*arg) {
24 res = strtoul(arg, &ptr, 0); 24 res = strtoul(arg, &ptr, 0);
25//FIXME: "" will be accepted too, is it correct?!
25 if (!*ptr && res <= UINT_MAX) { 26 if (!*ptr && res <= UINT_MAX) {
26 return res; 27 return res;
27 } 28 }
@@ -36,6 +37,7 @@ uint32_t get_u32(char *arg, const char *errmsg)
36 37
37 if (*arg) { 38 if (*arg) {
38 res = strtoul(arg, &ptr, 0); 39 res = strtoul(arg, &ptr, 0);
40//FIXME: "" will be accepted too, is it correct?!
39 if (!*ptr && res <= 0xFFFFFFFFUL) { 41 if (!*ptr && res <= 0xFFFFFFFFUL) {
40 return res; 42 return res;
41 } 43 }
@@ -50,6 +52,7 @@ uint16_t get_u16(char *arg, const char *errmsg)
50 52
51 if (*arg) { 53 if (*arg) {
52 res = strtoul(arg, &ptr, 0); 54 res = strtoul(arg, &ptr, 0);
55//FIXME: "" will be accepted too, is it correct?!
53 if (!*ptr && res <= 0xFFFF) { 56 if (!*ptr && res <= 0xFFFF) {
54 return res; 57 return res;
55 } 58 }
diff --git a/networking/tc.c b/networking/tc.c
index fc47e9571..d9636949c 100644
--- a/networking/tc.c
+++ b/networking/tc.c
@@ -89,7 +89,7 @@ static int get_qdisc_handle(__u32 *h, const char *str) {
89 if (p == str) 89 if (p == str)
90 return 1; 90 return 1;
91 maj <<= 16; 91 maj <<= 16;
92 if (*p != ':' && *p!=0) 92 if (*p != ':' && *p != '\0')
93 return 1; 93 return 1;
94 ok: 94 ok:
95 *h = maj; 95 *h = maj;
@@ -119,7 +119,8 @@ static int get_tc_classid(__u32 *h, const char *str) {
119 maj <<= 16; 119 maj <<= 16;
120 str = p + 1; 120 str = p + 1;
121 min = strtoul(str, &p, 16); 121 min = strtoul(str, &p, 16);
122 if (*p != 0 || min >= (1<<16)) 122//FIXME: check for "" too?
123 if (*p != '\0' || min >= (1<<16))
123 return 1; 124 return 1;
124 maj |= min; 125 maj |= min;
125 } else if (*p != 0) 126 } else if (*p != 0)
diff --git a/shell/ash.c b/shell/ash.c
index 68aa675e5..db28af7d3 100644
--- a/shell/ash.c
+++ b/shell/ash.c
@@ -10078,7 +10078,7 @@ change_random(const char *value)
10078 vrandom.flags &= ~VNOFUNC; 10078 vrandom.flags &= ~VNOFUNC;
10079 } else { 10079 } else {
10080 /* set/reset */ 10080 /* set/reset */
10081 random_galois_LFSR = random_LCG = strtoul(value, (char **)NULL, 10); 10081 random_galois_LFSR = random_LCG = strtoul(value, NULL, 10);
10082 } 10082 }
10083} 10083}
10084#endif 10084#endif