[PATCH:libX11 03/12] udcInf.c: convert sprintf calls to snprintf

Alan Coopersmith alan.coopersmith at oracle.com
Sat Aug 10 13:55:00 PDT 2013


Signed-off-by: Alan Coopersmith <alan.coopersmith at oracle.com>
---
 src/udcInf.c |   24 ++++++++++++------------
 1 file changed, 12 insertions(+), 12 deletions(-)

diff --git a/src/udcInf.c b/src/udcInf.c
index 9ecf156..faec421 100644
--- a/src/udcInf.c
+++ b/src/udcInf.c
@@ -131,7 +131,7 @@ int  *num_codeset;
 
     for(num=0;;num++){
         /* XLC_FONTSET */
-        sprintf(buf, "fs%d.font.primary", num);
+        snprintf(buf, sizeof(buf), "fs%d.font.primary", num);
         _XlcGetLocaleDataBase(lcd, "XLC_FONTSET", buf, &value, &count);
         if(count < 1){
             break ;
@@ -268,7 +268,7 @@ int  *num_gr;
     udc = NULL;
 
         /* XLC_FONTSET */
-        sprintf(buf, "fs%d.charset.udc_area", codeset-1);
+        snprintf(buf, sizeof(buf), "fs%d.charset.udc_area", codeset-1);
         _XlcGetLocaleDataBase(lcd, "XLC_FONTSET", buf, &value, &count);
         if(count > 0){
             udc = Xmalloc(count * sizeof(_XUDCGlyphRegion));
@@ -284,7 +284,7 @@ int  *num_gr;
 
     *num_gr = count;
 
-        sprintf(buf, "fs%d.font.primary", codeset-1);
+        snprintf(buf, sizeof(buf), "fs%d.font.primary", codeset-1);
         _XlcGetLocaleDataBase(lcd, "XLC_FONTSET", buf, &value, &count);
         if(count > 0){
 	    font_data = read_EncodingInfo(count,value);
@@ -330,14 +330,14 @@ int	size;
     FontData font_data;
 
 
-    sprintf(buf, "fs%d.charset.name", codeset-1);
+    snprintf(buf, sizeof(buf), "fs%d.charset.name", codeset-1);
     _XlcGetLocaleDataBase(lcd, "XLC_FONTSET", buf, &value, &count);
     if(count > 0){
         strcpy(charsetname,value[0]);
     }
     if (count >= size)
 	return False;
-    sprintf(buf, "fs%d.font.primary", codeset-1);
+    snprintf(buf, sizeof(buf), "fs%d.font.primary", codeset-1);
     _XlcGetLocaleDataBase(lcd, "XLC_FONTSET", buf, &value, &count);
     if(count > 0){
 	font_data = read_EncodingInfo(count,value);
@@ -369,7 +369,7 @@ XlcCharSet 	charset;
             return(False);
     }
     for(i=0;;i++){
-	sprintf(buf, "csd%d.charset_name", i);
+	snprintf(buf, sizeof(buf), "csd%d.charset_name", i);
 	_XlcGetLocaleDataBase(lcd, "XLC_CHARSET_DEFINE", buf, &value, &count);
 	if(count > 0){
 	    if(!_XlcNCompareISOLatin1(value[0],
@@ -463,9 +463,9 @@ unsigned long 	*codepoint;
     } else if(charset->ct_sequence){
 	if (strlen(charset->ct_sequence) + strlen(src) >= sizeof(from32))
 	    return(_XUDC_ERROR);
-        sprintf((char *)from,"%s%s",charset->ct_sequence,src);
+        snprintf((char *)from,sizeof(from32),"%s%s",charset->ct_sequence,src);
     } else {
-        sprintf((char *)from,"%s\0",src);
+        snprintf((char *)from,sizeof(from32),"%s\0",src);
     }
     /* compound text -> multi byte */
     conv = _XlcOpenConverter(lcd, XlcNCompoundText, lcd, XlcNMultiByte);
@@ -604,7 +604,7 @@ int	size;
 
 
     for(i=0;;i++){
-        sprintf(buf, "fs%d.charset.name",i);
+        snprintf(buf, sizeof(buf), "fs%d.charset.name",i);
         _XlcGetLocaleDataBase(lcd, "XLC_FONTSET", buf, &value, &count);
         if(count > 0){
             if(!_XlcNCompareISOLatin1(charset->name,value[0],
@@ -617,13 +617,13 @@ int	size;
 	}
     }
 /*
-    sprintf(buf, "fs%d.charset.name", codeset-1);
+    snprintf(buf, sizeof(buf), "fs%d.charset.name", codeset-1);
     _XlcGetLocaleDataBase(lcd, "XLC_FONTSET", buf, &value, &count);
     if(count > 0){
         strcpy(charsetname,value[0]);
     }
 */
-    sprintf(buf, "fs%d.font.primary", i);
+    snprintf(buf, sizeof(buf), "fs%d.font.primary", i);
     _XlcGetLocaleDataBase(lcd, "XLC_FONTSET", buf, &value, &count);
     if(count > 0){
 	font_data = read_EncodingInfo(count,value);
@@ -677,7 +677,7 @@ int 		*num_gi;
 	}
     }
     src[j] = 0;
-    sprintf((char *)from,"%s\0",src);
+    snprintf((char *)from, sizeof(from32), "%s\0", src);
     /* multi byte -> vgi */
     conv = _XlcOpenConverter(lcd, XlcNMultiByte, lcd, XlcNCharSet);
     from_left = strlen((char *)from);
-- 
1.7.9.2



More information about the xorg-devel mailing list