<div dir="ltr"><div><div><div>You do know you can implement an asprintf-alike using vsnprintf, right?<br></div></div></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Tue, Oct 29, 2013 at 9:51 PM, Alan Coopersmith <span dir="ltr"><<a href="mailto:alan.coopersmith@oracle.com" target="_blank">alan.coopersmith@oracle.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Most were fixed length or length checked anyway, this just saves time<br>
doublechecking that. (A few could be replaced by asprintf, but we<br>
don't have a copy guaranteed to be reachable from this program yet.)<br>
<br>
Signed-off-by: Alan Coopersmith <<a href="mailto:alan.coopersmith@oracle.com">alan.coopersmith@oracle.com</a>><br>
---<br>
expr.c | 2 +-<br>
geometry.c | 10 +++++-----<br>
listing.c | 9 +++++----<br>
xkbcomp.c | 4 ++--<br>
4 files changed, 13 insertions(+), 12 deletions(-)<br>
<br>
diff --git a/expr.c b/expr.c<br>
index 96fd956..195e0f3 100644<br>
--- a/expr.c<br>
+++ b/expr.c<br>
@@ -767,7 +767,7 @@ ExprResolveString(ExprDef * expr,<br>
new = (char *) uAlloc(len);<br>
if (new)<br>
{<br>
- sprintf(new, "%s%s", leftRtrn.str, rightRtrn.str);<br>
+ snprintf(new, len, "%s%s", leftRtrn.str, rightRtrn.str);<br>
val_rtrn->str = new;<br>
return True;<br>
}<br>
diff --git a/geometry.c b/geometry.c<br>
index 7f65c3a..cfd1f51 100644<br>
--- a/geometry.c<br>
+++ b/geometry.c<br>
@@ -258,9 +258,9 @@ ddText(Display * dpy, DoodadInfo * di)<br>
}<br>
if (di->section)<br>
{<br>
- sprintf(buf, "%s in section %s",<br>
- XkbAtomText(dpy, di->name, XkbMessage), scText(dpy,<br>
- di->section));<br>
+ snprintf(buf, sizeof(buf), "%s in section %s",<br>
+ XkbAtomText(dpy, di->name, XkbMessage),<br>
+ scText(dpy, di->section));<br>
return buf;<br>
}<br>
return XkbAtomText(dpy, di->name, XkbMessage);<br>
@@ -3297,8 +3297,8 @@ FontFromParts(Atom fontTok,<br>
rtrn = uCalloc(totalSize, 1);<br>
if (rtrn)<br>
{<br>
- sprintf(rtrn, FONT_TEMPLATE, font, weight, slant, setWidth, variant,<br>
- size, encoding);<br>
+ snprintf(rtrn, totalSize, FONT_TEMPLATE, font, weight, slant,<br>
+ setWidth, variant, size, encoding);<br>
}<br>
return rtrn;<br>
}<br>
diff --git a/listing.c b/listing.c<br>
index 11de88a..c7f5ef8 100644<br>
--- a/listing.c<br>
+++ b/listing.c<br>
@@ -302,18 +302,19 @@ AddDirectory(char *head, char *ptrn, char *rest, char *map)<br>
{<br>
char *tmp, *filename;<br>
struct stat sbuf;<br>
+ size_t tmpsize;<br>
<br>
filename = FileName(file);<br>
if (!filename || filename[0] == '.')<br>
continue;<br>
if (ptrn && (!XkbNameMatchesPattern(filename, ptrn)))<br>
continue;<br>
- tmp =<br>
- (char *) uAlloc((head ? strlen(head) : 0) + strlen(filename) + 2);<br>
+ tmpsize = (head ? strlen(head) : 0) + strlen(filename) + 2;<br>
+ tmp = uAlloc(tmpsize);<br>
if (!tmp)<br>
continue;<br>
- sprintf(tmp, "%s%s%s", (head ? head : ""), (head ? "/" : ""),<br>
- filename);<br>
+ snprintf(tmp, tmpsize, "%s%s%s",<br>
+ (head ? head : ""), (head ? "/" : ""), filename);<br>
if (stat(tmp, &sbuf) < 0)<br>
{<br>
uFree(tmp);<br>
diff --git a/xkbcomp.c b/xkbcomp.c<br>
index a4ee359..956e79c 100644<br>
--- a/xkbcomp.c<br>
+++ b/xkbcomp.c<br>
@@ -745,7 +745,7 @@ parseArgs(int argc, char *argv[])<br>
ACTION("Exiting\n");<br>
exit(1);<br>
}<br>
- sprintf(outputFile, "stdin.%s", fileTypeExt[outputFormat]);<br>
+ snprintf(outputFile, len, "stdin.%s", fileTypeExt[outputFormat]);<br>
}<br>
else if ((outputFile == NULL) && (inputFile != NULL))<br>
{<br>
@@ -773,7 +773,7 @@ parseArgs(int argc, char *argv[])<br>
}<br>
ext = strrchr(base, '.');<br>
if (ext == NULL)<br>
- sprintf(outputFile, "%s.%s", base, fileTypeExt[outputFormat]);<br>
+ snprintf(outputFile, len, "%s.%s", base, fileTypeExt[outputFormat]);<br>
else<br>
{<br>
strcpy(outputFile, base);<br>
<span class="HOEnZb"><font color="#888888">--<br>
1.7.9.2<br>
<br>
_______________________________________________<br>
<a href="mailto:xorg-devel@lists.x.org">xorg-devel@lists.x.org</a>: X.Org development<br>
Archives: <a href="http://lists.x.org/archives/xorg-devel" target="_blank">http://lists.x.org/archives/xorg-devel</a><br>
Info: <a href="http://lists.x.org/mailman/listinfo/xorg-devel" target="_blank">http://lists.x.org/mailman/listinfo/xorg-devel</a><br>
</font></span></blockquote></div><br><br clear="all"><br>-- <br> Jasper<br>
</div>