summaryrefslogtreecommitdiff
path: root/misc.c
diff options
context:
space:
mode:
authorivmai <ivmai>2011-04-20 23:25:18 +0200
committerIvan Maidanski <ivmai@mail.ru>2011-07-26 19:06:58 +0200
commit83e0a2cefcbc88bdbc19bcf98cc3a1f1cf307d63 (patch)
tree3ed52e8e4f037f5cf6bd6ba54b3f5099028da7c7 /misc.c
parentaf1726c615b5af04e3fe20b8782c1560aac41f7f (diff)
2011-04-20 Ivan Maidanski <ivmai@mail.ru>
* misc.c (GC_parse_mem_size_arg): Allow 'k', 'M', 'G' suffixes in heap size specifier; return 0 if not a valid one. * include/gc_cpp.h: Explicitly define inline one-argument delete operator for Cygwin (as a workaround). * include/gc_cpp.h: Reformat the code. * tests/test_cpp.cc: Ditto. * tests/test_cpp.cc (main): Suppress compiler warnings about "assigned value is unused".
Diffstat (limited to 'misc.c')
-rw-r--r--misc.c30
1 files changed, 28 insertions, 2 deletions
diff --git a/misc.c b/misc.c
index 59bdd12..ee6fa96 100644
--- a/misc.c
+++ b/misc.c
@@ -636,8 +636,34 @@ STATIC void GC_exit_check(void)
STATIC word GC_parse_mem_size_arg(const char *str)
{
char *endptr;
- word result = (word)STRTOULL(str, &endptr, 10);
- /* TODO: allow 'k', 'M', 'G' suffix */
+ word result = 0; /* bad value */
+ char ch;
+
+ if (*str != '\0') {
+ result = (word)STRTOULL(str, &endptr, 10);
+ ch = *endptr;
+ if (ch != '\0') {
+ if (*(endptr + 1) != '\0')
+ return 0;
+ /* Allow k, M or G suffix. */
+ switch (ch) {
+ case 'K':
+ case 'k':
+ result <<= 10;
+ break;
+ case 'M':
+ case 'm':
+ result <<= 20;
+ break;
+ case 'G':
+ case 'g':
+ result <<= 30;
+ break;
+ default:
+ result = 0;
+ }
+ }
+ }
return result;
}