Commit 61bfeeb7 authored by Paul Eggert's avatar Paul Eggert
Browse files

Avoid the use of snprintf.

* font.c (APPEND_SNPRINTF): Remove.
(font_unparse_xlfd):
* xterm.c (x_io_error_quitter):
Use esnprintf, not snprintf.  That way, we don't have to worry
about porting to ancient platforms that lack snprintf.
(x_term_init): Use sprintf, not snprintf.
parent 0999621a
2011-08-31 Paul Eggert <eggert@cs.ucla.edu>
Avoid the use of snprintf.
* font.c (APPEND_SNPRINTF): Remove.
(font_unparse_xlfd):
* xterm.c (x_io_error_quitter):
Use esnprintf, not snprintf. That way, we don't have to worry
about porting to ancient platforms that lack snprintf.
(x_term_init): Use sprintf, not snprintf.
2011-08-30 Paul Eggert <eggert@cs.ucla.edu> 2011-08-30 Paul Eggert <eggert@cs.ucla.edu>
sprintf-related integer and memory overflow issues (Bug#9412). sprintf-related integer and memory overflow issues (Bug#9412).
......
...@@ -1285,14 +1285,14 @@ font_unparse_xlfd (Lisp_Object font, int pixel_size, char *name, int nbytes) ...@@ -1285,14 +1285,14 @@ font_unparse_xlfd (Lisp_Object font, int pixel_size, char *name, int nbytes)
} }
else else
f[XLFD_AVGWIDTH_INDEX] = "*"; f[XLFD_AVGWIDTH_INDEX] = "*";
len = snprintf (name, nbytes, "-%s-%s-%s-%s-%s-%s-%s-%s-%s-%s-%s", len = esnprintf (name, nbytes, "-%s-%s-%s-%s-%s-%s-%s-%s-%s-%s-%s",
f[XLFD_FOUNDRY_INDEX], f[XLFD_FAMILY_INDEX], f[XLFD_FOUNDRY_INDEX], f[XLFD_FAMILY_INDEX],
f[XLFD_WEIGHT_INDEX], f[XLFD_SLANT_INDEX], f[XLFD_WEIGHT_INDEX], f[XLFD_SLANT_INDEX],
f[XLFD_SWIDTH_INDEX], f[XLFD_ADSTYLE_INDEX], f[XLFD_SWIDTH_INDEX], f[XLFD_ADSTYLE_INDEX],
f[XLFD_PIXEL_INDEX], f[XLFD_RESX_INDEX], f[XLFD_PIXEL_INDEX], f[XLFD_RESX_INDEX],
f[XLFD_SPACING_INDEX], f[XLFD_AVGWIDTH_INDEX], f[XLFD_SPACING_INDEX], f[XLFD_AVGWIDTH_INDEX],
f[XLFD_REGISTRY_INDEX]); f[XLFD_REGISTRY_INDEX]);
return len < nbytes ? len : -1; return len == nbytes - 1 ? -1 : len;
} }
/* Parse NAME (null terminated) and store information in FONT /* Parse NAME (null terminated) and store information in FONT
...@@ -1592,39 +1592,32 @@ font_unparse_fcname (Lisp_Object font, int pixel_size, char *name, int nbytes) ...@@ -1592,39 +1592,32 @@ font_unparse_fcname (Lisp_Object font, int pixel_size, char *name, int nbytes)
p = name; p = name;
lim = name + nbytes; lim = name + nbytes;
# define APPEND_SNPRINTF(args) \
do { \
int len = snprintf args; \
if (! (0 <= len && len < lim - p)) \
return -1; \
p += len; \
} while (0)
if (! NILP (family)) if (! NILP (family))
APPEND_SNPRINTF ((p, lim - p, "%s", SSDATA (family))); p += esnprintf (p, lim - p, "%s", SSDATA (family));
if (point_size > 0) if (point_size > 0)
APPEND_SNPRINTF ((p, lim - p, "-%d" + (p == name), point_size)); p += esnprintf (p, lim - p, "-%d" + (p == name), point_size);
else if (pixel_size > 0) else if (pixel_size > 0)
APPEND_SNPRINTF ((p, lim - p, ":pixelsize=%d", pixel_size)); p += esnprintf (p, lim - p, ":pixelsize=%d", pixel_size);
if (! NILP (AREF (font, FONT_FOUNDRY_INDEX))) if (! NILP (AREF (font, FONT_FOUNDRY_INDEX)))
APPEND_SNPRINTF ((p, lim - p, ":foundry=%s", p += esnprintf (p, lim - p, ":foundry=%s",
SSDATA (SYMBOL_NAME (AREF (font, SSDATA (SYMBOL_NAME (AREF (font,
FONT_FOUNDRY_INDEX))))); FONT_FOUNDRY_INDEX))));
for (i = 0; i < 3; i++) for (i = 0; i < 3; i++)
if (! NILP (styles[i])) if (! NILP (styles[i]))
APPEND_SNPRINTF ((p, lim - p, ":%s=%s", style_names[i], p += esnprintf (p, lim - p, ":%s=%s", style_names[i],
SSDATA (SYMBOL_NAME (styles[i])))); SSDATA (SYMBOL_NAME (styles[i])));
if (INTEGERP (AREF (font, FONT_DPI_INDEX))) if (INTEGERP (AREF (font, FONT_DPI_INDEX)))
APPEND_SNPRINTF ((p, lim - p, ":dpi=%"pI"d", p += esnprintf (p, lim - p, ":dpi=%"pI"d",
XINT (AREF (font, FONT_DPI_INDEX)))); XINT (AREF (font, FONT_DPI_INDEX)));
if (INTEGERP (AREF (font, FONT_SPACING_INDEX))) if (INTEGERP (AREF (font, FONT_SPACING_INDEX)))
APPEND_SNPRINTF ((p, lim - p, ":spacing=%"pI"d", p += esnprintf (p, lim - p, ":spacing=%"pI"d",
XINT (AREF (font, FONT_SPACING_INDEX)))); XINT (AREF (font, FONT_SPACING_INDEX)));
if (INTEGERP (AREF (font, FONT_AVGWIDTH_INDEX))) if (INTEGERP (AREF (font, FONT_AVGWIDTH_INDEX)))
APPEND_SNPRINTF ((p, lim - p, p += esnprintf (p, lim - p,
(XINT (AREF (font, FONT_AVGWIDTH_INDEX)) == 0 (XINT (AREF (font, FONT_AVGWIDTH_INDEX)) == 0
? ":scalable=true" ? ":scalable=true"
: ":scalable=false"))); : ":scalable=false"));
return (p - name); return lim - p == 1 ? -1 : p - name;
} }
/* Parse NAME (null terminated) and store information in FONT /* Parse NAME (null terminated) and store information in FONT
......
...@@ -7900,8 +7900,8 @@ x_io_error_quitter (Display *display) ...@@ -7900,8 +7900,8 @@ x_io_error_quitter (Display *display)
{ {
char buf[256]; char buf[256];
snprintf (buf, sizeof buf, "Connection lost to X server `%s'", esnprintf (buf, sizeof buf, "Connection lost to X server `%s'",
DisplayString (display)); DisplayString (display));
x_connection_closed (display, buf); x_connection_closed (display, buf);
return 0; return 0;
} }
...@@ -10278,8 +10278,8 @@ x_term_init (Lisp_Object display_name, char *xrm_option, char *resource_name) ...@@ -10278,8 +10278,8 @@ x_term_init (Lisp_Object display_name, char *xrm_option, char *resource_name)
atom_names[i] = (char *) atom_refs[i].name; atom_names[i] = (char *) atom_refs[i].name;
/* Build _XSETTINGS_SN atom name */ /* Build _XSETTINGS_SN atom name */
snprintf (xsettings_atom_name, sizeof (xsettings_atom_name), sprintf (xsettings_atom_name,
"_XSETTINGS_S%d", XScreenNumberOfScreen (dpyinfo->screen)); "_XSETTINGS_S%d", XScreenNumberOfScreen (dpyinfo->screen));
atom_names[i] = xsettings_atom_name; atom_names[i] = xsettings_atom_name;
XInternAtoms (dpyinfo->display, atom_names, total_atom_count, XInternAtoms (dpyinfo->display, atom_names, total_atom_count,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment