Fix memory violation when smushing at line start
Smushing characters at the line start can cause the next character to be copied to an offset before the start of the line buffer. In this case, add an offset to source and copy to a valid destination position. Signed-off-by: Claudio Matsuoka <cmatsuoka@gmail.com>
This commit is contained in:
parent
7a76594dbd
commit
caf8b1fcfd
12
figlet.c
12
figlet.c
@ -1424,7 +1424,7 @@ int smushamt()
|
||||
int addchar(c)
|
||||
inchr c;
|
||||
{
|
||||
int smushamount,row,k;
|
||||
int smushamount,row,k,column,offset;
|
||||
char *templine;
|
||||
|
||||
getletter(c);
|
||||
@ -1434,6 +1434,7 @@ inchr c;
|
||||
return 0;
|
||||
}
|
||||
|
||||
offset = 0;
|
||||
templine = (char*)myalloc(sizeof(char)*(outlinelenlimit+1));
|
||||
for (row=0;row<charheight;row++) {
|
||||
if (right2left) {
|
||||
@ -1447,8 +1448,13 @@ inchr c;
|
||||
}
|
||||
else {
|
||||
for (k=0;k<smushamount;k++) {
|
||||
outputline[row][outlinelen-smushamount+k] =
|
||||
smushem(outputline[row][outlinelen-smushamount+k],currchar[row][k]);
|
||||
column = outlinelen-smushamount+k;
|
||||
if (column < 0) {
|
||||
offset = -column;
|
||||
column = 0;
|
||||
}
|
||||
outputline[row][column] =
|
||||
smushem(outputline[row][column],currchar[row][k + offset]);
|
||||
}
|
||||
strcat(outputline[row],currchar[row]+smushamount);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user