dbgf: Don't print beyond last buffer char

This commit is contained in:
Andrew Johnson
2016-08-24 20:17:36 -05:00
parent e5d0915b51
commit 3963dcb4df

View File

@@ -950,7 +950,9 @@ static void printBuffer(
}
else {
for (i = 0; i < no_elements; i+= MAXLINE - 5) {
sprintf(pmsg, " \"%.*s\"", MAXLINE - 5, (char *)pbuffer + i);
int width = no_elements - i;
if (width > MAXLINE - 5) width = MAXLINE - 5;
sprintf(pmsg, " \"%.*s\"", width, (char *)pbuffer + i);
if (i + MAXLINE - 5 < no_elements) strcat(pmsg, " +");
dbpr_msgOut(pMsgBuff, tab_size);
}