Skip to content

Commit 243f3cb

Browse files
committed
common BUGFIX avoid 0 size for realloc
1 parent 106f6e0 commit 243f3cb

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

src/common.c

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5782,17 +5782,19 @@ sr_xpath_get_text_pred_atoms(const char *xpath, char ***xp_atoms, uint32_t *xp_a
57825782
goto cleanup;
57835783
}
57845784

5785-
/* add a new atom */
5786-
mem = realloc(*xp_atoms, (*xp_atom_count + atom_count) * sizeof **xp_atoms);
5787-
SR_CHECK_MEM_GOTO(!mem, err_info, cleanup);
5788-
*xp_atoms = mem;
5785+
if (atom_count) {
5786+
/* add a new atom */
5787+
mem = realloc(*xp_atoms, (*xp_atom_count + atom_count) * sizeof **xp_atoms);
5788+
SR_CHECK_MEM_GOTO(!mem, err_info, cleanup);
5789+
*xp_atoms = mem;
57895790

5790-
for (i = 0; i < atom_count; ++i) {
5791-
(*xp_atoms)[*xp_atom_count] = atoms[i].atom;
5792-
++(*xp_atom_count);
5793-
atoms[i].atom = NULL;
5791+
for (i = 0; i < atom_count; ++i) {
5792+
(*xp_atoms)[*xp_atom_count] = atoms[i].atom;
5793+
++(*xp_atom_count);
5794+
atoms[i].atom = NULL;
5795+
}
5796+
free(atoms);
57945797
}
5795-
free(atoms);
57965798

57975799
/* move to expr after the union */
57985800
xpath = next + 1;

0 commit comments

Comments
 (0)