The length limit imposed on safeStrCpy was one too short when copying
an existing comment to the space allocated for the longer (concatenated)
one. It allowed no space for the terminating '\0'.
while(commentList[index][oldlen-1] == '\n')
commentList[index][--oldlen] = NULLCHAR;
commentList[index] = (char *) malloc(oldlen + len + 6); // might waste 4
- safeStrCpy(commentList[index], old, oldlen);
+ safeStrCpy(commentList[index], old, oldlen + len + 6);
free(old);
// [HGM] braces: join "{A\n}\n" + "{\nB}" as "{A\nB\n}"
if(commentList[index][oldlen-1] == '}' && (text[0] == '{' || addBraces)) {