Browse code

properly handle return value of vsnprintf

git-svn: trunk@1867

Tomasz Kojm authored on 2006/03/23 02:59:54
Showing 2 changed files
... ...
@@ -1,3 +1,8 @@
1
+Wed Mar 22 18:44:25 CET 2006 (tk)
2
+---------------------------------
3
+  * shared/output.c: properly handle return value of vsnprintf
4
+		     Thanks to Anton Yuzhaninov <citrin*rambler-co.ru>
5
+
1 6
 Wed Mar 22 13:14:52 CET 2006 (tk)
2 7
 ---------------------------------
3 8
   * docs/man: multiple manpage typo fixes (patch by A. Costa <agcosta*gis.net>)
... ...
@@ -88,8 +88,15 @@ int mdprintf(int desc, const char *str, ...)
88 88
 	int bytes;
89 89
 
90 90
     va_start(args, str);
91
-    bytes = vsnprintf(buff, 512, str, args);
91
+    bytes = vsnprintf(buff, sizeof(buff), str, args);
92 92
     va_end(args);
93
+
94
+    if(bytes == -1)
95
+	return bytes;
96
+
97
+    if(bytes >= sizeof(buff))
98
+	bytes = sizeof(buff) - 1;
99
+
93 100
     return send(desc, buff, bytes, 0);
94 101
 }
95 102