ethtool: Can't parse ints with stroul()
Subsystems (2)
PATCH 1/1 ethtool: Can't parse ints with stroul()
From: PJ Waskiewicz <[email protected]>
A recent change to how int's were being parsed from the command line had them being read in with an unsigned int string operator. This didn't allow signed numbers from being read in correctly. This patch adds a get_uint() routine, and fixes the get_int() routine to read in signed values.
---
ethtool.c | 21 ++++++++++++++++++++- 1 files changed, 20 insertions(+), 1 deletions(-)
ethtool.c +20 -1
@@ -324,6 +324,7 @@ typedef enum {CMDL_NONE ,CMDL_BOOL ,CMDL_INT , +CMDL_UINT ,CMDL_STR , } cmdline_type_t;
@@ -404,6 +405,20 @@ static struct cmdline_info cmdline_coalesce[] = {static int get_int (char *str,int base) { +long v; +char *endp; + +if (!str) +show_usage (1 ); + errno =0 ; + v =strtol (str, &endp, base); +if ( errno || *endp || v >INT_MAX ) +show_usage (1 ); +return (int )v; +} + +static int get_uint (char *str,int base) +{unsigned long v;char *endp;
@@ -413,7 +428,7 @@ static int get_int(char *str, int base) v =strtoul (str, &endp, base);if ( errno || *endp || v >INT_MAX )show_usage (1 ); -return (int )v; +return v; } static void parse_generic_cmdline(int argc, char **argp,
@@ -447,6 +462,10 @@ static void parse_generic_cmdline(int argc, char **argp, *p =get_int (argp[i],0 );break ; } +case CMDL_UINT : { + *p =get_uint (argp[i],0 ); +break ; + }case CMDL_STR : {char **s = info[idx].wanted_val; *s =strdup (argp[i]);
Quoted 8 lines · Jeff Kirsher
From: PJ Waskiewicz <[email protected]>
A recent change to how int's were being parsed from the command line had them being read in with an unsigned int string operator. This didn't allow signed numbers from being read in correctly. This patch adds a
get_uint()routine, and fixes theget_int()routine to read in signed values.
Quoted 4 lines
Signed-off-by Peter P Waskiewicz Jr <[email protected]>Signed-off-by Jeff Kirsher <[email protected]>---
Jeff G. - hold off on this patch. We have a version 2 in the works, because we found if the sign bit was set on a uint, this would fail parsing.
Signature · 2 lines
Cheers, Jeff
Quoted 9 lines · Jeff Kirsher
Quoted 8 lines · Jeff Kirsher
From: PJ Waskiewicz<[email protected]>
A recent change to how int's were being parsed from the command line had them being read in with an unsigned int string operator. This didn't allow signed numbers from being read in correctly. This patch adds a
get_uint()routine, and fixes theget_int()routine to read in signed values.
Quoted 8 lines
Quoted 4 lines
Signed-off-by Peter P Waskiewicz Jr<[email protected]>Signed-off-by Jeff Kirsher<[email protected]>---
Jeff G. - hold off on this patch. We have a version 2 in the works, because we found if the sign bit was set on a uint, this would fail parsing.
Was version 2 ever posted? I never saw it...
Jeff
Quoted 18 lines · Jeff Garzik
Quoted 17 lines · Jeff Kirsher
Quoted 13 lines · Jeff Kirsher
From: PJ Waskiewicz<[email protected]>
A recent change to how int's were being parsed from the command line had them being read in with an unsigned int string operator. This didn't allow signed numbers from being read in correctly. This patch adds a
get_uint()routine, and fixes theget_int()routine to read in signed values.Signed-off-by Peter P Waskiewicz Jr<[email protected]>Signed-off-by Jeff Kirsher<[email protected]>---
Quoted 8 lines
Quoted 3 lines
Jeff G. - hold off on this patch. We have a version 2 in the works, because we found if the sign bit was set on a uint, this would fail parsing.
Was version 2 ever posted? I never saw it...
Jeff
Not yet, version 2 of the patch is in test right now. I should have it sent out either later tonight or tomorrow.
Signature · 2 lines
Cheers, Jeff