C segfault – off-by-one – Invalid write of size 1

I'm having some trouble with memory allocation in C.

I seem to always write or read to or from a wrong spot here, there's probably something I'm missing here:

char *a = malloc(8+b+1+c+1+d+1+e+1+e+4+6);
*(a+8+b+1+c+1+d+1+e+1+f+4+6) = '\0';

snprintf(a, strlen(a), "xyz    \"%sx%sx%sx%sx%s\"     ",v, w, x, y, z);

Could anyone help me get back on track?



Read more here: https://stackoverflow.com/questions/67013054/c-segfault-off-by-one-invalid-write-of-size-1

Content Attribution

This content was originally published by nacn at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: