Re: [PATCH v4 03/13] parseopt: make OPT_INTEGER support hexadecimal as well

2 messages, 2 authors, 2016-06-15 · open the first message on its own page

Re: [PATCH v4 03/13] parseopt: make OPT_INTEGER support hexadecimal as well

From: Junio C Hamano <hidden>
Date: 2016-06-15 22:52:56

Nguyen Thai Ngoc Duy [off-list ref] writes:
2012/2/4 Junio C Hamano [off-list ref]:
quoted
Nguyễn Thái Ngọc Duy  [off-list ref] writes:
quoted
-             *(int *)opt->value = strtol(arg, (char **)&s, 10);
+             if (!prefixcmp(arg, "0x") || !prefixcmp(arg, "0X"))
+                     *(int *)opt->value = strtol(arg + 2, (char **)&s, 16);
+             else
+                     *(int *)opt->value = strtol(arg, (char **)&s, 10);
Can't you just do "strtol(arg, (char **)&s, 0)" instead?
I could but that means "01234" is now in base 8 and that's currently
accepted as base 10.
Yes, but I wonder if that is a problem in practice. Who in the right mind
would give 00001000 to tell git that they want one thousand?

Re: [PATCH v4 03/13] parseopt: make OPT_INTEGER support hexadecimal as well

From: Nguyen Thai Ngoc Duy <hidden>
Date: 2016-06-15 22:52:56

On Sat, Feb 4, 2012 at 12:32 PM, Junio C Hamano [off-list ref] wrote:
Nguyen Thai Ngoc Duy [off-list ref] writes:
quoted
2012/2/4 Junio C Hamano [off-list ref]:
quoted
Nguyễn Thái Ngọc Duy  [off-list ref] writes:
quoted
-             *(int *)opt->value = strtol(arg, (char **)&s, 10);
+             if (!prefixcmp(arg, "0x") || !prefixcmp(arg, "0X"))
+                     *(int *)opt->value = strtol(arg + 2, (char **)&s, 16);
+             else
+                     *(int *)opt->value = strtol(arg, (char **)&s, 10);
Can't you just do "strtol(arg, (char **)&s, 0)" instead?
I could but that means "01234" is now in base 8 and that's currently
accepted as base 10.
Yes, but I wonder if that is a problem in practice. Who in the right mind
would give 00001000 to tell git that they want one thousand?
That could come from a script, extracting info from a source (maybe a
log file) and not stripping leading zeros. If we go this route, I
think we should have one release that rejects such numbers first. If
nobody complains, then we proceed and allow octal in the next release.
-- 
Duy
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help