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.
+
+2006-07-10 Behdad Esfahbod <behdad@gnome.org>
+
Bug 315599 – PangoAttribute remains in wrong context.
* pango/pangocairo-render.c (_pango_cairo_do_glyph_string): Rever my
* @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.
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;
}