rev 167 - trunk/src
SVN User <[email protected]>
| Newsgroups | gmane.comp.lang.prothon.cvs |
|---|---|
| Message-ID | <[email protected]> |
Author: bcollins
Date: 2004-03-27 19:25:27 -0500 (Sat, 27 Mar 2004)
New Revision: 167
Modified:
trunk/src/builtins.c
trunk/src/getline.c
trunk/src/sys.c
trunk/src/thread.c
Log:
Convert the rest of the sprintf usages to apr_snprintf. This also gives us
a bit of compatibility for things like %I64d on windows, can now be the
same as unix (since apr's snprintf is internally handled, it doesn't use
the windows version).
Modified: trunk/src/builtins.c
===================================================================
--- trunk/src/builtins.c 2004-03-28 00:16:31 UTC (rev 166)
+++ trunk/src/builtins.c 2004-03-28 00:25:27 UTC (rev 167)
@@ -55,6 +55,9 @@
#include <stdio.h>
#include <string.h>
+
+#include <apr_strings.h>
+
#include "object.h"
#include "interp.h"
@@ -142,8 +145,10 @@
char str[1024];
obj_p doc = get_attr(ist, self, SYM(__DOC__));
char* p = strch(doc);
- if (doc) sprintf(str, "<Object:%lx:%s>", (unsigned long)(uintptr_t)self, p);
- else sprintf(str, "<Object:%lx>", (unsigned long)(uintptr_t)self);
+ if (doc)
+ apr_snprintf(str, sizeof(str), "<Object:%lx:%s>", (unsigned long)(uintptr_t)self, p);
+ else
+ apr_snprintf(str, sizeof(str), "<Object:%lx>", (unsigned long)(uintptr_t)self);
return new_string_obj(str);
}
@@ -267,7 +272,7 @@
obj_p item = list_item(ist, self,i);
if ((uintptr_t)item > 10) item_str = as_str(ist, item);
else {
- sprintf(msg, "<objptr:%lx>", (unsigned long)(uintptr_t)item);
+ apr_snprintf(msg, sizeof(msg), "<objptr:%lx>", (unsigned long)(uintptr_t)item);
item_str = msg;
}
res = pr_realloc(res, strlen(res)+strlen(item_str)+4);
@@ -967,13 +972,17 @@
return new_int_obj(Int_value(self) << Int_value(other));
}
+#ifndef WIN32
+#define LONG_LONG_CAST (long long)
+#else
+#define LONG_LONG_CAST
+#endif
+
DEF(INT_OBJ, __str__, NULL){
char str[24];
-#ifdef WIN32
- sprintf(str, "%I64d", Int_value(self));
-#else
- sprintf(str, "%lld", (long long)Int_value(self));
-#endif
+
+ apr_snprintf(str, sizeof(str), "%lld", LONG_LONG_CAST Int_value(self));
+
return new_string_obj(str);
}
Modified: trunk/src/getline.c
===================================================================
--- trunk/src/getline.c 2004-03-28 00:16:31 UTC (rev 166)
+++ trunk/src/getline.c 2004-03-28 00:25:27 UTC (rev 167)
@@ -762,9 +762,9 @@
Gl_setwidth(wins.ws_col);
- sprintf(lenv, "LINES=%d", wins.ws_row);
+ apr_snprintf(lenv, sizeof(lenv), "LINES=%d", wins.ws_row);
putenv(lenv);
- sprintf(cenv, "COLUMNS=%d", wins.ws_col);
+ apr_snprintf(cenv, sizeof(cenv), "COLUMNS=%d", wins.ws_col);
putenv(cenv);
}
#endif
@@ -1399,7 +1399,7 @@
if (!strcmp(file, "-")) return;
- sprintf(gl_histfile, "%s", file);
+ apr_snprintf(gl_histfile, sizeof(gl_histfile), "%s", file);
fp = fopen(gl_histfile, "r");
if (fp)
Modified: trunk/src/sys.c
===================================================================
--- trunk/src/sys.c 2004-03-28 00:16:31 UTC (rev 166)
+++ trunk/src/sys.c 2004-03-28 00:25:27 UTC (rev 167)
@@ -53,6 +53,9 @@
// sys.c
+#ifndef WIN32
+#include <config.h>
+#endif
#include <stdlib.h>
#include <stdio.h>
@@ -62,7 +65,6 @@
#endif
#ifndef WIN32
-#include <config.h>
#include <unistd.h>
#include <limits.h>
#include <stdint.h>
@@ -244,8 +246,9 @@
if (!strncmp(p, "import ", 7)) {
char doc[300];
isp ist = get_ist();
- sprintf(modname, "PthMod%d", ++modname_cnt);
- sprintf(doc, ": a module loaded by %s", file_info.name);
+ apr_snprintf(modname, sizeof(modname), "PthMod%d", ++modname_cnt);
+ apr_snprintf(doc, sizeof(doc), ": a module loaded by %s",
+ file_info.name);
load_module( ist, sym(ist, modname), NULL, OBJ(OBJECT),
NULL, NULL, doc, NULL, p );
if (ist->exception_obj) check_exceptions(ist);
Modified: trunk/src/thread.c
===================================================================
--- trunk/src/thread.c 2004-03-28 00:16:31 UTC (rev 166)
+++ trunk/src/thread.c 2004-03-28 00:25:27 UTC (rev 167)
@@ -78,7 +78,7 @@
printf("Torture scan %d started\n", scan_num);
{
char tname[32];
- sprintf(tname, "tscan%d", scan_num);
+ apr_snprintf(tname, sizeof(tname), "tscan%d", scan_num);
SetThreadName(tname);
}