| 1 | Index: common/jk_map.c |
| 2 | =================================================================== |
| 3 | --- common/jk_map.c (revision 1535519) |
| 4 | +++ common/jk_map.c (working copy) |
| 5 | @@ -183,33 +183,37 @@ |
| 6 | |
| 7 | int jk_map_get_int(jk_map_t *m, const char *name, int def) |
| 8 | { |
| 9 | - char buf[100]; |
| 10 | const char *rc; |
| 11 | - size_t len; |
| 12 | int int_res; |
| 13 | - int multit = 1; |
| 14 | |
| 15 | - sprintf(buf, "%d", def); |
| 16 | - rc = jk_map_get_string(m, name, buf); |
| 17 | + rc = jk_map_get_string(m, name, NULL); |
| 18 | |
| 19 | - len = strlen(rc); |
| 20 | - if (len) { |
| 21 | - char *lastchar = &buf[0] + len - 1; |
| 22 | - strcpy(buf, rc); |
| 23 | - if ('m' == *lastchar || 'M' == *lastchar) { |
| 24 | - *lastchar = '\0'; |
| 25 | - multit = 1024 * 1024; |
| 26 | + if(NULL == rc) { |
| 27 | + int_res = def; |
| 28 | + } else { |
| 29 | + size_t len = strlen(rc); |
| 30 | + int multit = 1; |
| 31 | + |
| 32 | + if (len) { |
| 33 | + char buf[100]; |
| 34 | + char *lastchar; |
| 35 | + strncpy(buf, rc, 100); |
| 36 | + lastchar = buf + len - 1; |
| 37 | + if ('m' == *lastchar || 'M' == *lastchar) { |
| 38 | + *lastchar = '\0'; |
| 39 | + multit = 1024 * 1024; |
| 40 | + } |
| 41 | + else if ('k' == *lastchar || 'K' == *lastchar) { |
| 42 | + *lastchar = '\0'; |
| 43 | + multit = 1024; |
| 44 | + } |
| 45 | + int_res = multit * atoi(buf); |
| 46 | } |
| 47 | - else if ('k' == *lastchar || 'K' == *lastchar) { |
| 48 | - *lastchar = '\0'; |
| 49 | - multit = 1024; |
| 50 | - } |
| 51 | - int_res = atoi(buf); |
| 52 | + else |
| 53 | + int_res = def; |
| 54 | } |
| 55 | - else |
| 56 | - int_res = def; |
| 57 | |
| 58 | - return int_res * multit; |
| 59 | + return int_res; |
| 60 | } |
| 61 | |
| 62 | double jk_map_get_double(jk_map_t *m, const char *name, double def) |