@@ -920,10 +920,8 @@ static int cs2cs_emulation_setup(PJ *P) {
920
920
/* We ignore helmert if we have grid shift */
921
921
p = P->hgridshift ? nullptr : pj_param_exists (P->params , " towgs84" );
922
922
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 ;
927
925
928
926
/* We ignore null helmert shifts (common in auto-translated resource
929
927
* files, e.g. epsg) */
@@ -938,19 +936,17 @@ static int cs2cs_emulation_setup(PJ *P) {
938
936
break ;
939
937
}
940
938
939
+ const size_t n = strlen (s);
941
940
if (n <= 8 ) /* 8==strlen ("towgs84=") */
942
941
return 0 ;
943
942
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 ());
954
950
if (nullptr == Q)
955
951
return 0 ;
956
952
pj_inherit_ellipsoid_def (P, Q);
0 commit comments