Skip to content

Commit 8b36c19

Browse files
committed
Fix false-positive compiler warning
Fixes the following false-positive warning of gcc (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0 in -m32 mode: ``` /home/even/proj/proj/src/4D_api.cpp: In function 'int cs2cs_emulation_setup(PJ*)': /home/even/proj/proj/src/4D_api.cpp:949:64: warning: '%s' directive output between 9 and 2147483645 bytes may cause result to exceed 'INT_MAX' [-Wformat-truncation=] 949 | "break_cs2cs_recursion proj=helmert exact %s " | ```
1 parent 5d9df64 commit 8b36c19

File tree

1 file changed

+10
-14
lines changed

1 file changed

+10
-14
lines changed

src/4D_api.cpp

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -920,10 +920,8 @@ static int cs2cs_emulation_setup(PJ *P) {
920920
/* We ignore helmert if we have grid shift */
921921
p = P->hgridshift ? nullptr : pj_param_exists(P->params, "towgs84");
922922
while (p) {
923-
char *def;
924-
char *s = p->param;
925-
double *d = P->datum_params;
926-
size_t n = strlen(s);
923+
const char *const s = p->param;
924+
const double *const d = P->datum_params;
927925

928926
/* We ignore null helmert shifts (common in auto-translated resource
929927
* files, e.g. epsg) */
@@ -938,19 +936,17 @@ static int cs2cs_emulation_setup(PJ *P) {
938936
break;
939937
}
940938

939+
const size_t n = strlen(s);
941940
if (n <= 8) /* 8==strlen ("towgs84=") */
942941
return 0;
943942

944-
size_t def_size = 100 + n;
945-
def = static_cast<char *>(malloc(def_size));
946-
if (nullptr == def)
947-
return 0;
948-
snprintf(def, def_size,
949-
"break_cs2cs_recursion proj=helmert exact %s "
950-
"convention=position_vector",
951-
s);
952-
Q = pj_create_internal(P->ctx, def);
953-
free(def);
943+
const size_t def_max_size = 100 + n;
944+
std::string def;
945+
def.reserve(def_max_size);
946+
def += "break_cs2cs_recursion proj=helmert exact ";
947+
def += s;
948+
def += " convention=position_vector";
949+
Q = pj_create_internal(P->ctx, def.c_str());
954950
if (nullptr == Q)
955951
return 0;
956952
pj_inherit_ellipsoid_def(P, Q);

0 commit comments

Comments
 (0)