diff options
author | Behdad Esfahbod <behdad@gnome.org> | 2006-07-10 21:22:21 +0000 |
---|---|---|
committer | Behdad Esfahbod <behdad@src.gnome.org> | 2006-07-10 21:22:21 +0000 |
commit | 43f6a587e67878837680524bdc8240224258fac3 (patch) | |
tree | 54fff66185ebd6c8119eb210694f03ef3fea9e14 /pango | |
parent | bd0dcaf874333fa30660ea8d109a274eb45b0e7e (diff) | |
download | pango-43f6a587e67878837680524bdc8240224258fac3.tar.gz |
Bug 330603 – pango_scan_int invokes undefined behaviour
2006-07-10 Behdad Esfahbod <behdad@gnome.org>
Bug 330603 – pango_scan_int invokes undefined behaviour
* pango/pango-utils.c (pango_scan_int): Use strtol.
Diffstat (limited to 'pango')
-rw-r--r-- | pango/pango-utils.c | 36 |
1 files changed, 15 insertions, 21 deletions
diff --git a/pango/pango-utils.c b/pango/pango-utils.c index 70f32dbe..63976aed 100644 --- a/pango/pango-utils.c +++ b/pango/pango-utils.c @@ -412,8 +412,7 @@ pango_scan_string (const char **pos, GString *out) * @pos: in/out string position * @out: an int into which to write the result * - * Scans an integer. An integer consists - * of up to 31 decimal digits. + * Scans an integer. * Leading white space is skipped. * * Return value: %FALSE if a parse error occured. @@ -422,29 +421,24 @@ gboolean pango_scan_int (const char **pos, int *out) { unsigned int i = 0; - char buf[32]; - const char *p = *pos; - - while (g_ascii_isspace (*p)) - p++; - - if (*p < '0' || *p > '9') - return FALSE; + char *end; + long temp; - while ((*p >= '0') && (*p <= '9') && i < sizeof(buf)) + errno = 0; + temp = strtol (*pos, &end, 10); + if (errno == ERANGE) { - buf[i] = *p; - i++; - p++; + errno = 0; + return FALSE; + } + + *out = (int)temp; + if ((long)(*out) != temp) + { + return FALSE; } - if (i == sizeof(buf)) - return FALSE; - else - buf[i] = '\0'; - - *out = atoi (buf); - *pos = p; + *pos = end; return TRUE; } |