1
0
mirror of https://github.com/TREX-CoE/trexio.git synced 2024-12-22 20:35:44 +01:00

fix cppcheck warnings regarding redundant size_dset_str checks

This commit is contained in:
q-posev 2021-09-21 16:08:04 +02:00
parent d1a9af4185
commit 389d265f7f

View File

@ -483,49 +483,51 @@ trexio_text_read_$group$ (trexio_text_t* const file)
// START REPEAT GROUP_DSET_STR // START REPEAT GROUP_DSET_STR
/* Allocate arrays */ /* Allocate arrays */
$group$->$group_dset$ = CALLOC(size_$group_dset$, $group_dset_dtype$); if(size_$group_dset$ != 0) {
assert (!($group$->$group_dset$ == NULL)); $group$->$group_dset$ = CALLOC(size_$group_dset$, $group_dset_dtype$);
if ($group$->$group_dset$ == NULL) { assert (!($group$->$group_dset$ == NULL));
FREE(buffer); if ($group$->$group_dset$ == NULL) {
fclose(f); FREE(buffer);
FREE($group$->$group_dset$); fclose(f);
FREE($group$); FREE($group$->$group_dset$);
return NULL; FREE($group$);
} return NULL;
}
rc = fscanf(f, "%1023s", buffer);
assert(!((rc != 1) || (strcmp(buffer, "$group_dset$") != 0))); rc = fscanf(f, "%1023s", buffer);
if ((rc != 1) || (strcmp(buffer, "$group_dset$") != 0)) { assert(!((rc != 1) || (strcmp(buffer, "$group_dset$") != 0)));
FREE(buffer); if ((rc != 1) || (strcmp(buffer, "$group_dset$") != 0)) {
fclose(f); FREE(buffer);
FREE($group$->$group_dset$); fclose(f);
FREE($group$); FREE($group$->$group_dset$);
return NULL; FREE($group$);
} return NULL;
}
/* WARNING: this tmp array allows to avoid allocation of space for each element of array of string
, BUT it's size has to be number_of_str*max_len_str where max_len_str is somewhat arbitrary, e.g. 32. /* WARNING: this tmp array allows to avoid allocation of space for each element of array of string
,*/ , BUT it's size has to be number_of_str*max_len_str where max_len_str is somewhat arbitrary, e.g. 32.
char* tmp_$group_dset$; ,*/
if(size_$group_dset$ != 0) tmp_$group_dset$ = CALLOC(size_$group_dset$*32, char); char* tmp_$group_dset$;
tmp_$group_dset$ = CALLOC(size_$group_dset$*32, char);
for (uint64_t i=0 ; i<size_$group_dset$ ; ++i) {
$group$->$group_dset$[i] = tmp_$group_dset$; for (uint64_t i=0 ; i<size_$group_dset$ ; ++i) {
/* conventional fcanf with "%s" only return the string before the first space character $group$->$group_dset$[i] = tmp_$group_dset$;
,* to read string with spaces use "%[^\n]" possible with space before or after, i.e. " %[^\n]" /* conventional fcanf with "%s" only return the string before the first space character
,* Q: depending on what ? */ ,* to read string with spaces use "%[^\n]" possible with space before or after, i.e. " %[^\n]"
rc = fscanf(f, " %1023[^\n]", tmp_$group_dset$); ,* Q: depending on what ? */
assert(!(rc != 1)); rc = fscanf(f, " %1023[^\n]", tmp_$group_dset$);
if (rc != 1) { assert(!(rc != 1));
FREE(buffer); if (rc != 1) {
fclose(f); FREE(buffer);
FREE($group$->$group_dset$); fclose(f);
FREE($group$); FREE($group$->$group_dset$);
return NULL; FREE($group$);
return NULL;
}
size_t tmp_$group_dset$_len = strlen($group$->$group_dset$[i]);
tmp_$group_dset$ += tmp_$group_dset$_len + 1;
} }
size_t tmp_$group_dset$_len = strlen($group$->$group_dset$[i]);
tmp_$group_dset$ += tmp_$group_dset$_len + 1;
} }
// END REPEAT GROUP_DSET_STR // END REPEAT GROUP_DSET_STR