Skip to content

Commit

Permalink
Fix unpack empty strings (or pad remaining as necessary)
Browse files Browse the repository at this point in the history
  • Loading branch information
attipaci committed Oct 7, 2024
1 parent e5229f0 commit edb1605
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/smax-util.c
Original file line number Diff line number Diff line change
Expand Up @@ -1152,12 +1152,18 @@ int smaxUnpackStrings(const char *data, int len, int count, char **dst) {
dst[i] = (char *) malloc(l+1);
if(!dst[i]) return x_error(X_INCOMPLETE, errno, fn, "malloc() error (%d bytes)", (l+1));

memcpy(dst[i], from, l);
if(l) memcpy(dst[i], from, l);
dst[i][l] = '\0'; // termination...

offset += l;
}

// Pad remaining elements with empty strings...
for(; i < count; i++) {
dst[i] = calloc(1, sizeof(char));
if(!dst[i]) return x_error(X_INCOMPLETE, errno, fn, "calloc() error (1x1 byte)");
}

return X_SUCCESS;
}

Expand Down

0 comments on commit edb1605

Please sign in to comment.