Changeset: d2464f6ad90e for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/d2464f6ad90e
Modified Files:
clients/examples/C/smack00.c
clients/examples/C/smack01.c
clients/mapiclient/ReadlineTools.c
gdk/gdk_system.c
geom/monetdb5/geom_atoms.c
monetdb5/mal/mal_import.c
monetdb5/mal/mal_interpreter.c
monetdb5/mal/mal_linker.c
monetdb5/mal/mal_listing.c
monetdb5/modules/atoms/json.c
monetdb5/modules/mal/bbp.c
monetdb5/modules/mal/clients.c
monetdb5/modules/mal/mal_mapi.c
monetdb5/modules/mal/orderidx.c
monetdb5/modules/mal/querylog.c
monetdb5/modules/mal/remote.c
monetdb5/modules/mal/tablet.c
monetdb5/optimizer/opt_remap.c
monetdb5/optimizer/opt_remoteQueries.c
sql/backends/monet5/UDF/pyapi3/pyapi3.c
sql/backends/monet5/for.c
sql/backends/monet5/rel_bin.c
sql/backends/monet5/sql_execute.c
sql/backends/monet5/sql_gencode.c
sql/backends/monet5/vaults/csv/csv.c
sql/backends/monet5/vaults/fits/fits.c
sql/backends/monet5/vaults/netcdf/netcdf.c
sql/common/sql_types.c
sql/server/rel_dump.c
sql/server/rel_prop.c
sql/server/rel_propagate.c
sql/server/sql_mvc.c
sql/storage/bat/bat_logger.c
tools/merovingian/daemon/discoveryrunner.c
tools/merovingian/daemon/handlers.c
tools/merovingian/utils/properties.c
tools/monetdbe/monetdbe.c
Branch: Mar2025
Log Message:
Use sizeof if we need the size of a declared array.
diffs (truncated from 1063 to 300 lines):
diff --git a/clients/examples/C/smack00.c b/clients/examples/C/smack00.c
--- a/clients/examples/C/smack00.c
+++ b/clients/examples/C/smack00.c
@@ -65,9 +65,9 @@ main(int argc, char **argv)
for (i = 0; i < n; i++) {
if (lang==1)
- snprintf(buf, 40, "select %d;", i);
+ snprintf(buf, sizeof(buf), "select %d;", i);
else
- snprintf(buf, 40, "io.print(%d);", i);
+ snprintf(buf, sizeof(buf), "io.print(%d);", i);
if ((hdl = mapi_query(dbh, buf)) == NULL || mapi_error(dbh))
die(dbh, hdl);
while ( (/*line= */ mapi_fetch_line(hdl)) != NULL) {
diff --git a/clients/examples/C/smack01.c b/clients/examples/C/smack01.c
--- a/clients/examples/C/smack01.c
+++ b/clients/examples/C/smack01.c
@@ -70,9 +70,9 @@ main(int argc, char **argv)
die(dbh,NULL);
if (lang==1)
- snprintf(buf, 40, "select %d;", i);
+ snprintf(buf, sizeof(buf), "select %d;", i);
else
- snprintf(buf, 40, "io.print(%d);", i);
+ snprintf(buf, sizeof(buf), "io.print(%d);", i);
if ((hdl = mapi_query(dbh, buf)) == NULL || mapi_error(dbh))
die(dbh, hdl);
while ((line = mapi_fetch_line(hdl))) {
diff --git a/clients/mapiclient/ReadlineTools.c
b/clients/mapiclient/ReadlineTools.c
--- a/clients/mapiclient/ReadlineTools.c
+++ b/clients/mapiclient/ReadlineTools.c
@@ -369,7 +369,7 @@ invoke_editor(int cnt, int key) {
}
}
- snprintf(editor_command, BUFFER_SIZE, "%s %s", editor, template);
+ snprintf(editor_command, sizeof(editor_command), "%s %s", editor,
template);
if (system(editor_command) != 0) {
readline_show_error("invoke_editor: Starting editor failed\n");
goto bailout;
@@ -472,7 +472,7 @@ init_readline(Mapi mid, const char *lang
if (save_history) {
int len;
if (getenv("HOME") != NULL) {
- len = snprintf(_history_file, FILENAME_MAX,
+ len = snprintf(_history_file, sizeof(_history_file),
"%s/.mapiclient_history_%s",
getenv("HOME"), language);
if (len == -1 || len >= FILENAME_MAX)
diff --git a/gdk/gdk_system.c b/gdk/gdk_system.c
--- a/gdk/gdk_system.c
+++ b/gdk/gdk_system.c
@@ -979,7 +979,7 @@ MT_create_thread(MT_Id *t, void (*f) (vo
/* overwrite XXXX with thread ID; bottom three bits are
* likely 0, so skip those */
char buf[5];
- snprintf(buf, 5, "%04zu", self->tid % 9999);
+ snprintf(buf, sizeof(buf), "%04zu", self->tid % 9999);
memcpy(p, buf, 4);
}
TRC_DEBUG(THRD, "Create thread \"%s\"\n", self->threadname);
diff --git a/geom/monetdb5/geom_atoms.c b/geom/monetdb5/geom_atoms.c
--- a/geom/monetdb5/geom_atoms.c
+++ b/geom/monetdb5/geom_atoms.c
@@ -378,7 +378,7 @@ mbrTOSTR(char **dst, size_t *len, const
size_t dstStrLen;
if (!is_mbr_nil(atom)) {
- dstStrLen = (size_t) snprintf(tempWkt, MBR_WKTLEN,
+ dstStrLen = (size_t) snprintf(tempWkt, sizeof(tempWkt),
"BOX (%f %f, %f %f)",
atom->xmin, atom->ymin,
atom->xmax, atom->ymax);
diff --git a/monetdb5/mal/mal_import.c b/monetdb5/mal/mal_import.c
--- a/monetdb5/mal/mal_import.c
+++ b/monetdb5/mal/mal_import.c
@@ -57,7 +57,7 @@ malResolveFile(const char *fname)
str script;
int written;
- written = snprintf(path, FILENAME_MAX, "%s", fname);
+ written = snprintf(path, sizeof(path), "%s", fname);
if (written == -1 || written >= FILENAME_MAX)
return NULL;
slash_2_dir_sep(path);
diff --git a/monetdb5/mal/mal_interpreter.c b/monetdb5/mal/mal_interpreter.c
--- a/monetdb5/mal/mal_interpreter.c
+++ b/monetdb5/mal/mal_interpreter.c
@@ -1178,7 +1178,7 @@ runMALsequence(Client cntxt, MalBlkPtr m
ret = MAL_SUCCEED;
if (getVarType(mb, getDestVar(pci)) == TYPE_str) {
char nme[256];
- snprintf(nme, 256, "%s.%s[%d]",
getModuleId(getInstrPtr(mb, 0)),
+ snprintf(nme, sizeof(nme), "%s.%s[%d]",
getModuleId(getInstrPtr(mb, 0)),
getFunctionId(getInstrPtr(mb,
0)), stkpc);
ret = createException(MAL, nme, "%s",
stk->stk[getDestVar(pci)].val.sval);
@@ -1247,7 +1247,7 @@ runMALsequence(Client cntxt, MalBlkPtr m
/* don't add 'exception not caught' extra message for MAL sequences
besides main function calls */
if (exceptionVar >= 0 && (ret == MAL_SUCCEED || !pcicaller)) {
char nme[256];
- snprintf(nme, 256, "%s.%s[%d]", getModuleId(getInstrPtr(mb, 0)),
+ snprintf(nme, sizeof(nme), "%s.%s[%d]",
getModuleId(getInstrPtr(mb, 0)),
getFunctionId(getInstrPtr(mb, 0)), stkpc);
if (ret != MAL_SUCCEED) {
str new, n;
diff --git a/monetdb5/mal/mal_linker.c b/monetdb5/mal/mal_linker.c
--- a/monetdb5/mal/mal_linker.c
+++ b/monetdb5/mal/mal_linker.c
@@ -185,11 +185,11 @@ loadLibrary(const char *filename, int fl
int len;
if (is_mod && flag < 0)
- len = snprintf(nme, FILENAME_MAX, ".%c%s_%s%s",
DIR_SEP, SO_PREFIX, s, SO_EXT);
+ len = snprintf(nme, sizeof(nme), ".%c%s_%s%s", DIR_SEP,
SO_PREFIX, s, SO_EXT);
else if (is_mod)
- len = snprintf(nme, FILENAME_MAX, "%s_%s%s", SO_PREFIX,
s, SO_EXT);
+ len = snprintf(nme, sizeof(nme), "%s_%s%s", SO_PREFIX,
s, SO_EXT);
else
- len = snprintf(nme, FILENAME_MAX, "%s%s%s", SO_PREFIX,
s, SO_EXT);
+ len = snprintf(nme, sizeof(nme), "%s%s%s", SO_PREFIX,
s, SO_EXT);
if (len == -1 || len >= FILENAME_MAX)
throw(LOADER, "loadLibrary",
RUNTIME_LOAD_ERROR "Library filename path is
too large");
@@ -222,11 +222,11 @@ loadLibrary(const char *filename, int fl
;
if (is_mod)
- len = snprintf(nme, FILENAME_MAX, "%.*s%c%s_%s%s",
+ len = snprintf(nme, sizeof(nme), "%.*s%c%s_%s%s",
(int) (p - mod_path),
mod_path, DIR_SEP, SO_PREFIX,
s, SO_EXT);
else
- len = snprintf(nme, FILENAME_MAX, "%.*s%c%s%s%s",
+ len = snprintf(nme, sizeof(nme), "%.*s%c%s%s%s",
(int) (p - mod_path),
mod_path, DIR_SEP, SO_PREFIX,
s, SO_EXT);
if (len == -1 || len >= FILENAME_MAX)
@@ -241,11 +241,11 @@ loadLibrary(const char *filename, int fl
if (handle == NULL && strcmp(SO_EXT, ".so") != /* DISABLES CODE
*/ (0)) {
/* try .so */
if (is_mod)
- len = snprintf(nme, FILENAME_MAX,
"%.*s%c%s_%s.so",
+ len = snprintf(nme, sizeof(nme),
"%.*s%c%s_%s.so",
(int) (p -
mod_path), mod_path, DIR_SEP,
SO_PREFIX, s);
else
- len = snprintf(nme, FILENAME_MAX,
"%.*s%c%s%s.so",
+ len = snprintf(nme, sizeof(nme),
"%.*s%c%s%s.so",
(int) (p -
mod_path), mod_path, DIR_SEP,
SO_PREFIX, s);
if (len == -1 || len >= FILENAME_MAX)
@@ -262,11 +262,11 @@ loadLibrary(const char *filename, int fl
if (handle == NULL && strcmp(SO_EXT, ".bundle") != 0) {
/* try .bundle */
if (is_mod)
- len = snprintf(nme, FILENAME_MAX,
"%.*s%c%s_%s.bundle",
+ len = snprintf(nme, sizeof(nme),
"%.*s%c%s_%s.bundle",
(int) (p -
mod_path), mod_path, DIR_SEP,
SO_PREFIX, s);
else
- len = snprintf(nme, FILENAME_MAX,
"%.*s%c%s%s.bundle",
+ len = snprintf(nme, sizeof(nme),
"%.*s%c%s%s.bundle",
(int) (p -
mod_path), mod_path, DIR_SEP,
SO_PREFIX, s);
if (len == -1 || len >= FILENAME_MAX)
diff --git a/monetdb5/mal/mal_listing.c b/monetdb5/mal/mal_listing.c
--- a/monetdb5/mal/mal_listing.c
+++ b/monetdb5/mal/mal_listing.c
@@ -175,7 +175,7 @@ cfcnDefinition(Symbol s, str base, size_
char var[16];
for (i = f->retc; i < f->argc; i++) {
- if (snprintf(var, 16, "X_%d:", i-f->retc) >= 16 ||
!copystring(&t, var, &len))
+ if (snprintf(var, sizeof(var), "X_%d:", i-f->retc) >= 16 ||
!copystring(&t, var, &len))
return base;
if ((f->args[i].isbat || (f->args[i].opt == 1)) &&
!copystring(&t, (f->args[i].opt == 1)?"bat?[:":"bat[:", &len))
return base;
@@ -184,7 +184,7 @@ cfcnDefinition(Symbol s, str base, size_
return base;
if (!arg[0]) {
if (f->args[i].nr) {
- if (snprintf(var, 16, "any_%d", f->args[i].nr )
>= 16 || !copystring(&t, var, &len))
+ if (snprintf(var, sizeof(var), "any_%d",
f->args[i].nr ) >= 16 || !copystring(&t, var, &len))
return base;
} else if (!copystring(&t, "any", &len))
return base;
@@ -212,7 +212,7 @@ cfcnDefinition(Symbol s, str base, size_
return base;
if (!tpe[0]) {
if (f->args[0].nr) {
- if (snprintf(var, 16, "any_%d", f->args[0].nr )
>= 16 || !copystring(&t, var, &len))
+ if (snprintf(var, sizeof(var), "any_%d",
f->args[0].nr ) >= 16 || !copystring(&t, var, &len))
return base;
} else if (!copystring(&t, "any", &len))
return base;
@@ -225,7 +225,7 @@ cfcnDefinition(Symbol s, str base, size_
if (!copystring(&t, ") (", &len))
return base;
for (i = 0; i < f->retc; i++) {
- if (snprintf(var, 16, "X_%d:", i+(f->argc-f->retc)) >=
16 || !copystring(&t, var, &len))
+ if (snprintf(var, sizeof(var), "X_%d:",
i+(f->argc-f->retc)) >= 16 || !copystring(&t, var, &len))
return base;
if ((f->args[i].isbat || (f->args[i].opt == 1)) &&
!copystring(&t, (f->args[i].opt == 1)?"bat?[:":"bat[:", &len))
return base;
@@ -234,7 +234,7 @@ cfcnDefinition(Symbol s, str base, size_
return base;
if (!arg[0]) {
if (f->args[i].nr) {
- if (snprintf(var, 16, "any_%d",
f->args[i].nr ) >= 16 || !copystring(&t, var, &len))
+ if (snprintf(var, sizeof(var),
"any_%d", f->args[i].nr ) >= 16 || !copystring(&t, var, &len))
return base;
} else if (!copystring(&t, "any", &len))
return base;
@@ -330,13 +330,13 @@ fcnDefinition(MalBlkPtr mb, InstrPtr p,
char extra[256];
if (p->token == REMsymbol) {
} else {
- snprintf(extra, 256, "\t#[%d] (" BUNFMT ") %s ",
getPC(mb, p),
+ snprintf(extra, sizeof(extra), "\t#[%d] (" BUNFMT ") %s
", getPC(mb, p),
getRowCnt(mb, getArg(p, 0)),
(p->blk ? p->blk->binding : ""));
if (!copystring(&t, extra, &len))
return base;
for (j = 0; j < p->retc; j++) {
- snprintf(extra, 256, "%d ", getArg(p, j));
+ snprintf(extra, sizeof(extra), "%d ", getArg(p,
j));
if (!copystring(&t, extra, &len))
return base;
}
@@ -345,7 +345,7 @@ fcnDefinition(MalBlkPtr mb, InstrPtr p,
return base;
}
for (; j < p->argc; j++) {
- snprintf(extra, 256, "%d ", getArg(p, j));
+ snprintf(extra, sizeof(extra), "%d ", getArg(p,
j));
if (!copystring(&t, extra, &len))
return base;
}
@@ -376,9 +376,9 @@ fmtRemark(MalBlkPtr mb, MalStkPtr stk, I
long a2 = atol(arg);
const char *f = getFunctionId(pci);
if (strcmp(f, "total") == 0)
- snprintf(aux, 128, "%d optimizers %ld usecs",
a1, a2);
+ snprintf(aux, sizeof(aux), "%d optimizers %ld
usecs", a1, a2);
else
- snprintf(aux, 128, "%-36s %d actions %ld
usecs", f, a1, a2);
+ snprintf(aux, sizeof(aux), "%-36s %d actions
%ld usecs", f, a1, a2);
(void) copystring(&t, aux, &len);
}
} else if (pci->argc == 1) {
@@ -574,13 +574,13 @@ instruction2str(MalBlkPtr mb, MalStkPtr
char extra[256];
if (p->token == REMsymbol) {
} else {
- snprintf(extra, 256, "\t#[%d] (" BUNFMT ") %s ", p->pc,
+ snprintf(extra, sizeof(extra), "\t#[%d] (" BUNFMT ") %s
", p->pc,
getRowCnt(mb, getArg(p, 0)),
(p->blk ? p->blk->binding : ""));
if (!copystring(&t, extra, &len))
return base;
for (j = 0; j < p->retc; j++) {
- snprintf(extra, 256, "%d ", getArg(p, j));
+ snprintf(extra, sizeof(extra), "%d ", getArg(p,
j));
if (!copystring(&t, extra, &len))
return base;
}
@@ -589,7 +589,7 @@ instruction2str(MalBlkPtr mb, MalStkPtr
return base;
}
for (; j < p->argc; j++) {
- snprintf(extra, 256, "%d ", getArg(p, j));
+ snprintf(extra, sizeof(extra), "%d ", getArg(p,
j));
if (!copystring(&t, extra, &len))
return base;
}
diff --git a/monetdb5/modules/atoms/json.c b/monetdb5/modules/atoms/json.c
--- a/monetdb5/modules/atoms/json.c
+++ b/monetdb5/modules/atoms/json.c
@@ -1517,7 +1517,7 @@ JSONfilterArrayDefault(json *ret, const
if (index < 0)
throw(MAL, "json.filter",
SQLSTATE(42000) "Filter index cannot be negative");
- snprintf(expr, BUFSIZ, "[" LLFMT "]", index);
+ snprintf(expr, sizeof(expr), "[" LLFMT "]", index);
return JSONfilterInternal(ret, js, &(const char *){s}, other);
}
diff --git a/monetdb5/modules/mal/bbp.c b/monetdb5/modules/mal/bbp.c
--- a/monetdb5/modules/mal/bbp.c
+++ b/monetdb5/modules/mal/bbp.c
@@ -193,7 +193,7 @@ CMDbbpLocation(bat *ret)
for (i = 1; i < getBBPsize(); i++)
if (i != b->batCacheid) {
if (BBP_logical(i) && (BBP_refs(i) || BBP_lrefs(i))) {
- int len = snprintf(buf, FILENAME_MAX,
"%s/bat/%s", cwd,
+ int len = snprintf(buf, sizeof(buf),
"%s/bat/%s", cwd,
BBP_physical(i));
_______________________________________________
checkin-list mailing list -- [email protected]
To unsubscribe send an email to [email protected]