[Freeciv-Dev] (PR#12635) Use freeciv specific functions instead of the "
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
<URL: http://bugs.freeciv.org/Ticket/Display.html?id=12635 >
Mostly prefixing with "my". I change some snprints to cat_snprints.
Jason: How far does this closes PR#10436: forbidden functions in FTWL?
Also attached are the new scripts for finding these cases. They should
be added to the tests dir.
Raimar
--
email: i-freeciv-lists@xxxxxxxxxxxxx
"We've all heard that a million monkeys banging on a million typewriters
will eventually reproduce the entire works of Shakespeare.
Now, thanks to the Internet, we know this is not true."
? files
? native_functions1.diff
? data/themes/morgan/1024x768
Index: client/helpdata.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/helpdata.c,v
retrieving revision 1.96
diff -u -u -r1.96 helpdata.c
--- client/helpdata.c 14 Mar 2005 20:26:24 -0000 1.96
+++ client/helpdata.c 25 Mar 2005 12:05:14 -0000
@@ -1441,7 +1441,7 @@
if (any == 0) {
/* strcpy(buf, _("None")); */
- snprintf(buf, sizeof(buf), "%d", 0);
+ my_snprintf(buf, sizeof(buf), "%d", 0);
}
return buf;
}
Index: client/tilespec.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/tilespec.c,v
retrieving revision 1.275
diff -u -u -r1.275 tilespec.c
--- client/tilespec.c 23 Mar 2005 17:49:38 -0000 1.275
+++ client/tilespec.c 25 Mar 2005 12:05:24 -0000
@@ -1479,8 +1479,8 @@
for (i = 0; i < t->num_cardinal_tileset_dirs; i++) {
int value = (idx >> i) & 1;
- snprintf(c + strlen(c), sizeof(c) - strlen(c), "%s%d",
- dir_get_tileset_name(t->cardinal_tileset_dirs[i]), value);
+ cat_snprintf(c, sizeof(c), "%s%d",
+ dir_get_tileset_name(t->cardinal_tileset_dirs[i]), value);
}
return c;
@@ -1499,8 +1499,8 @@
for (i = 0; i < t->num_valid_tileset_dirs; i++) {
int value = (index >> i) & 1;
- snprintf(c + strlen(c), sizeof(c) - strlen(c), "%s%d",
- dir_get_tileset_name(t->valid_tileset_dirs[i]), value);
+ cat_snprintf(c, sizeof(c), "%s%d",
+ dir_get_tileset_name(t->valid_tileset_dirs[i]), value);
}
return c;
@@ -1696,10 +1696,12 @@
for (j = 0; j < t->num_valid_tileset_dirs / 2; j++) {
int value = (i >> j) & 1;
- snprintf(c + strlen(c), sizeof(c) - strlen(c), "%s%d",
- dir_get_tileset_name(t->valid_tileset_dirs[2 * j]), value);
- snprintf(d + strlen(d), sizeof(d) - strlen(d), "%s%d",
- dir_get_tileset_name(t->valid_tileset_dirs[2 * j + 1]), value);
+ cat_snprintf(c, sizeof(c), "%s%d",
+ dir_get_tileset_name(t->valid_tileset_dirs[2 * j]),
+ value);
+ cat_snprintf(d, sizeof(d), "%s%d",
+ dir_get_tileset_name(t->valid_tileset_dirs[2 * j + 1]),
+ value);
}
my_snprintf(buffer, sizeof(buffer), "r.c_road_%s", c);
Index: client/gui-ftwl/mapview.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-ftwl/mapview.c,v
retrieving revision 1.18
diff -u -u -r1.18 mapview.c
--- client/gui-ftwl/mapview.c 25 Mar 2005 10:31:52 -0000 1.18
+++ client/gui-ftwl/mapview.c 25 Mar 2005 12:05:30 -0000
@@ -896,7 +896,7 @@
}
for (i = 0; i < 8; i++) {
- if (strcasecmp(dir_str, dir_get_name(i)) == 0) {
+ if (mystrcasecmp(dir_str, dir_get_name(i)) == 0) {
dir = i;
found = TRUE;
break;
Index: common/aicore/cm.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/aicore/cm.c,v
retrieving revision 1.60
diff -u -u -r1.60 cm.c
--- common/aicore/cm.c 16 Mar 2005 19:37:49 -0000 1.60
+++ common/aicore/cm.c 25 Mar 2005 12:05:39 -0000
@@ -1944,16 +1944,12 @@
****************************************************************************/
#ifdef CM_DEBUG
static void snprint_production(char *buffer, size_t bufsz,
- const int production[])
+ const int production[])
{
- int nout;
-
- nout = snprintf(buffer, bufsz, "[%d %d %d %d %d %d]",
- production[O_FOOD], production[O_SHIELD],
- production[O_TRADE], production[O_GOLD],
- production[O_LUXURY], production[O_SCIENCE]);
-
- assert(nout >= 0 && nout <= bufsz);
+ my_snprintf(buffer, bufsz, "[%d %d %d %d %d %d]",
+ production[O_FOOD], production[O_SHIELD],
+ production[O_TRADE], production[O_GOLD],
+ production[O_LUXURY], production[O_SCIENCE]);
}
/****************************************************************************
@@ -1964,7 +1960,7 @@
{
char prodstr[256];
- snprint_production(prodstr, sizeof(prodstr), ptype->production);
+ my_snprint_production(prodstr, sizeof(prodstr), ptype->production);
freelog(loglevel, "%s%s fitness %g depth %d, idx %d; %d tiles", prefix,
prodstr, ptype->estimated_fitness, ptype->lattice_depth,
ptype->lattice_index, tile_type_num_tiles(ptype));
@@ -1999,14 +1995,14 @@
freelog(loglevel, "** completed solution:");
}
- snprint_production(buf, sizeof(buf), soln->production);
+ my_snprint_production(buf, sizeof(buf), soln->production);
freelog(loglevel, "production: %s", buf);
freelog(loglevel, "tiles used:");
for (i = 0; i < num_types(state); i++) {
if (soln->worker_counts[i] != 0) {
- snprintf(buf, sizeof(buf),
- " %d tiles of type ", soln->worker_counts[i]);
+ my_snprintf(buf, sizeof(buf), " %d tiles of type ",
+ soln->worker_counts[i]);
print_tile_type(loglevel, tile_type_get(state, i), buf);
}
}
Index: manual/civmanual.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/manual/civmanual.c,v
retrieving revision 1.8
diff -u -u -r1.8 civmanual.c
--- manual/civmanual.c 3 Jan 2005 03:31:44 -0000 1.8
+++ manual/civmanual.c 25 Mar 2005 12:05:43 -0000
@@ -112,7 +112,7 @@
for (manuals = 0; manuals < MANUAL_COUNT; manuals++) {
int i;
- snprintf(filename, sizeof(filename), "manual%d.html", manuals + 1);
+ my_snprintf(filename, sizeof(filename), "manual%d.html", manuals + 1);
if (!is_reg_file_for_access(filename, TRUE)
|| !(doc = fopen(filename, "w"))) {
Index: server/savegame.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/savegame.c,v
retrieving revision 1.229
diff -u -u -r1.229 savegame.c
--- server/savegame.c 22 Mar 2005 04:03:35 -0000 1.229
+++ server/savegame.c 25 Mar 2005 12:05:49 -0000
@@ -418,7 +418,7 @@
for (a = 0; a < ACTIVITY_LAST; a++) {
char achar = activity2char(a);
- if (activity == achar || activity == toupper(achar)) {
+ if (activity == achar || activity == my_toupper(achar)) {
return a;
}
}
Index: utility/fciconv.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/utility/fciconv.c,v
retrieving revision 1.13
diff -u -u -r1.13 fciconv.c
--- utility/fciconv.c 23 Mar 2005 20:27:08 -0000 1.13
+++ utility/fciconv.c 25 Mar 2005 12:05:49 -0000
@@ -200,9 +200,8 @@
assert(text != NULL);
if (cd == (iconv_t) (-1)) {
- freelog(LOG_ERROR,
- _("Could not convert text from %s to %s: %s"),
- from, to, strerror(errno));
+ freelog(LOG_ERROR, _("Could not convert text from %s to %s: %s"), from,
+ to, mystrerror());
/* The best we can do? */
if (alloc) {
return mystrdup(text);
Index: utility/ftwl/be_common_24.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/utility/ftwl/be_common_24.c,v
retrieving revision 1.10
diff -u -u -r1.10 be_common_24.c
--- utility/ftwl/be_common_24.c 22 Mar 2005 21:40:54 -0000 1.10
+++ utility/ftwl/be_common_24.c 25 Mar 2005 12:05:50 -0000
@@ -639,7 +639,7 @@
void be_write_osda_to_file(struct osda *osda, const char *filename)
{
FILE *file;
- unsigned char *line_buffer = malloc(3 * osda->image->width), *pout;
+ unsigned char *line_buffer = fc_malloc(3 * osda->image->width), *pout;
int x, y;
file = fopen(filename, "w");
Index: utility/ftwl/common_types.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/utility/ftwl/common_types.c,v
retrieving revision 1.3
diff -u -u -r1.3 common_types.c
--- utility/ftwl/common_types.c 22 Jan 2005 19:45:45 -0000 1.3
+++ utility/ftwl/common_types.c 25 Mar 2005 12:05:51 -0000
@@ -285,8 +285,8 @@
{
static char buffer[100];
- snprintf(buffer, 100, "{x=%d, y=%d, width=%d, height=%d}", rect->x,
- rect->y, rect->width, rect->height);
+ my_snprintf(buffer, 100, "{x=%d, y=%d, width=%d, height=%d}", rect->x,
+ rect->y, rect->width, rect->height);
return buffer;
}
@@ -463,15 +463,16 @@
{
static char out[100];
char buffer[100];
+
if (key->type == BE_KEY_NORMAL) {
- snprintf(buffer, sizeof(buffer), "%c", key->key);
+ my_snprintf(buffer, sizeof(buffer), "%c", key->key);
} else {
int i;
bool found = FALSE;
for (i = 0; i < ARRAY_SIZE(keymap); i++) {
if (keymap[i].type == key->type) {
- snprintf(buffer, sizeof(buffer), "%s", keymap[i].name);
+ my_snprintf(buffer, sizeof(buffer), "%s", keymap[i].name);
found = TRUE;
break;
}
@@ -479,7 +480,7 @@
assert(found);
}
- snprintf(out, sizeof(out), "%s%s%s%s",
+ my_snprintf(out, sizeof(out), "%s%s%s%s",
(key->alt ? "Alt-" : ""),
(key->control ? "Ctrl-" : ""),
(key->shift ? "Shift-" : ""), buffer);
find_native_functions.sh
Description: Bourne shell script
import sys
a="""
snprintf=cat_snprintf my_snprintf my_vsnprintf
strcasecmp=mystrcasecmp
strncasecmp=mystrncasecmp
usleep=myusleep usleep_since_timer_start
strerror=mystrerror fz_strerror snd_strerror
gethostname=my_gethostname
malloc=fc_malloc real_malloc sbuf_malloc get_option_malloc
local_to_internal_string_malloc internal_to_data_string_malloc
data_to_internal_string_malloc _string_malloc
calloc= fc_calloc real_calloc
realloc=fc_realloc real_realloc
strdup=mystrdup g_strdup_printf g_strdup_vprintf sbuf_strdup minstrdup unistrdup
readsocket=my_readsocket
writesocket=my_writesocket
strlcpy=mystrlcpy sz_strlcpy name_strlcpy g_strlcpy loud_strlcpy
strlcat=mystrlcat sz_strlcat
isalnum=my_isalnum
isalpha=my_isalpha
isdigit=my_isdigit
isprint=my_isprint
isspace=my_isspace g_unichar_isspace
isupper=my_isupper
toupper=my_toupper
tolower=my_tolower
"""
# maps from the native function to valid uses
m={}
for line in a.split("\n"):
if not line: continue
key,value=line.split("=")
values=value.split(" ")
m[key]=values
lines=sys.stdin.readlines()
for line in lines:
for key in m.keys():
if line.find(key)==-1: continue
ok=0
for pos in m[key]:
if line.find(pos)!=-1:
ok=1
break
if not ok:
print "%s: %s"%(sys.argv[1],line),
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Freeciv-Dev] (PR#12635) Use freeciv specific functions instead of the "raw" ones,
Raimar Falke <=
|
|