[libxslt] Replace sprintf with snprintf



commit a48c1a861052511f964495347af9e1cbe23d4609
Author: David Kilzer <ddkilzer webkit org>
Date:   Wed Feb 24 16:56:13 2016 +0100

    Replace sprintf with snprintf
    
    Fixes bug #758202
    https://bugzilla.gnome.org/show_bug.cgi?id=758202

 libxslt/functions.c |    4 ++--
 libxslt/xsltutils.c |   28 ++++++++++++++--------------
 2 files changed, 16 insertions(+), 16 deletions(-)
---
diff --git a/libxslt/functions.c b/libxslt/functions.c
index 6448bde..549649c 100644
--- a/libxslt/functions.c
+++ b/libxslt/functions.c
@@ -703,9 +703,9 @@ xsltGenerateIdFunction(xmlXPathParserContextPtr ctxt, int nargs){
 
     val = (long)((char *)cur - (char *)&base_address);
     if (val >= 0) {
-      sprintf((char *)str, "idp%ld", val);
+      snprintf((char *)str, sizeof(str), "idp%ld", val);
     } else {
-      sprintf((char *)str, "idm%ld", -val);
+      snprintf((char *)str, sizeof(str), "idm%ld", -val);
     }
     valuePush(ctxt, xmlXPathNewString(str));
 }
diff --git a/libxslt/xsltutils.c b/libxslt/xsltutils.c
index 75232fc..c7d9f1e 100644
--- a/libxslt/xsltutils.c
+++ b/libxslt/xsltutils.c
@@ -2087,9 +2087,9 @@ xsltSaveProfiling(xsltTransformContextPtr ctxt, FILE *output) {
                 break;
             }
             t=templ2?templ2->time:totalt;
-            sprintf(times_str,"%8.3f",(float)t/XSLT_TIMESTAMP_TICS_PER_SEC);
-            sprintf(timec_str,"%8.3f",(float)childt[k]/XSLT_TIMESTAMP_TICS_PER_SEC);
-            sprintf(called_str,"%6d/%d",
+            snprintf(times_str,sizeof(times_str),"%8.3f",(float)t/XSLT_TIMESTAMP_TICS_PER_SEC);
+            snprintf(timec_str,sizeof(timec_str),"%8.3f",(float)childt[k]/XSLT_TIMESTAMP_TICS_PER_SEC);
+            snprintf(called_str,sizeof(called_str),"%6d/%d",
                 templ1->templCountTab[j], /* number of times caller calls 'this' */
                 templ1->nbCalls);         /* total number of calls to 'this' */
 
@@ -2098,10 +2098,10 @@ xsltSaveProfiling(xsltTransformContextPtr ctxt, FILE *output) {
                 (templ2?(templ2->name?(char *)templ2->name:pretty_templ_match(templ2)):"-"),k);
         }
         /* this */
-        sprintf(ix_str,"[%d]",i);
-        sprintf(timep_str,"%6.2f",(float)templ1->time*100.0/totalt);
-        sprintf(times_str,"%8.3f",(float)templ1->time/XSLT_TIMESTAMP_TICS_PER_SEC);
-        sprintf(timec_str,"%8.3f",(float)childt[i]/XSLT_TIMESTAMP_TICS_PER_SEC);
+        snprintf(ix_str,sizeof(ix_str),"[%d]",i);
+        snprintf(timep_str,sizeof(timep_str),"%6.2f",(float)templ1->time*100.0/totalt);
+        snprintf(times_str,sizeof(times_str),"%8.3f",(float)templ1->time/XSLT_TIMESTAMP_TICS_PER_SEC);
+        snprintf(timec_str,sizeof(timec_str),"%8.3f",(float)childt[i]/XSLT_TIMESTAMP_TICS_PER_SEC);
         fprintf(output, "%-5s %-6s %-8s %-8s %6d     %s [%d]\n",
             ix_str, timep_str,times_str,timec_str,
             templ1->nbCalls,
@@ -2123,9 +2123,9 @@ xsltSaveProfiling(xsltTransformContextPtr ctxt, FILE *output) {
             templ2 = templates[k];
             for (l = 0; l < templ2->templNr; l++) {
                 if (templ2->templCalledTab[l] == templ1) {
-                    sprintf(times_str,"%8.3f",(float)templ2->time/XSLT_TIMESTAMP_TICS_PER_SEC);
-                    sprintf(timec_str,"%8.3f",(float)childt[k]/XSLT_TIMESTAMP_TICS_PER_SEC);
-                    sprintf(called_str,"%6d/%d",
+                    
snprintf(times_str,sizeof(times_str),"%8.3f",(float)templ2->time/XSLT_TIMESTAMP_TICS_PER_SEC);
+                    
snprintf(timec_str,sizeof(timec_str),"%8.3f",(float)childt[k]/XSLT_TIMESTAMP_TICS_PER_SEC);
+                    snprintf(called_str,sizeof(called_str),"%6d/%d",
                         templ2->templCountTab[l], /* number of times 'this' calls callee */
                         total);                   /* total number of calls from 'this' */
                     fprintf(output, "             %-8s %-8s %-12s     %s [%d]\n",
@@ -2245,19 +2245,19 @@ xsltGetProfileInformation(xsltTransformContextPtr ctxt)
 
     for (i = 0; i < nb; i++) {
         child = xmlNewChild(root, NULL, BAD_CAST "template", NULL);
-        sprintf(buf, "%d", i + 1);
+        snprintf(buf, sizeof(buf), "%d", i + 1);
         xmlSetProp(child, BAD_CAST "rank", BAD_CAST buf);
         xmlSetProp(child, BAD_CAST "match", BAD_CAST templates[i]->match);
         xmlSetProp(child, BAD_CAST "name", BAD_CAST templates[i]->name);
         xmlSetProp(child, BAD_CAST "mode", BAD_CAST templates[i]->mode);
 
-        sprintf(buf, "%d", templates[i]->nbCalls);
+        snprintf(buf, sizeof(buf), "%d", templates[i]->nbCalls);
         xmlSetProp(child, BAD_CAST "calls", BAD_CAST buf);
 
-        sprintf(buf, "%ld", templates[i]->time);
+        snprintf(buf, sizeof(buf), "%ld", templates[i]->time);
         xmlSetProp(child, BAD_CAST "time", BAD_CAST buf);
 
-        sprintf(buf, "%ld", templates[i]->time / templates[i]->nbCalls);
+        snprintf(buf, sizeof(buf), "%ld", templates[i]->time / templates[i]->nbCalls);
         xmlSetProp(child, BAD_CAST "average", BAD_CAST buf);
     };
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]