Skip to content

Commit

Permalink
fix: crash when too many elements in delayed output (as slurs)
Browse files Browse the repository at this point in the history
The size of the temporary buffer used for delayed output was not correct.
Now, this buffer is allocated from the heap with the same size as the
output normal buffer.

Issue #16.
  • Loading branch information
moinejf committed Apr 13, 2018
1 parent ae71e7d commit fd956e1
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
1 change: 1 addition & 0 deletions abcm2ps.h
Original file line number Diff line number Diff line change
Expand Up @@ -559,6 +559,7 @@ typedef struct SYMBOL *INFO[26]; /* information fields ('A' .. 'Z') */
extern INFO info;

extern char *outbuf; /* output buffer.. should hold one tune */
extern int outbufsz; /* size of outbuf */
extern char *mbf; /* where to PUTx() */
extern int use_buffer; /* 1 if lines are being accumulated */

Expand Down
2 changes: 1 addition & 1 deletion buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ static float remy; /* remaining vertical space in page */
static float bposy; /* current position in buffered data */
static int nepsf; /* counter for -E/-g output files */
static int nbpages; /* number of pages in the output file */
static int outbufsz; /* size of outbuf */
int outbufsz; /* size of outbuf */
static char outfnam[FILENAME_MAX]; /* internal file name for open/close */
static struct FORMAT *p_fmt; /* current format while treating a new page */

Expand Down
9 changes: 8 additions & 1 deletion music.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
*/

#include <string.h>
#include <stdlib.h>
#include <ctype.h>

#include "abcm2ps.h"
Expand Down Expand Up @@ -5068,10 +5069,15 @@ static void error_show(void)
static float delayed_output(float indent)
{
float line_height;
char *outbuf_sav, *mbf_sav, tmpbuf[20 * 1024];
char *outbuf_sav, *mbf_sav, *tmpbuf;

outbuf_sav = outbuf;
mbf_sav = mbf;
tmpbuf = malloc(outbufsz);
if (!tmpbuf) {
error(1, NULL, "Out of memory for delayed outbuf - abort");
exit(EXIT_FAILURE);
}
mbf = outbuf = tmpbuf;
*outbuf = '\0';
outft = -1;
Expand All @@ -5081,6 +5087,7 @@ static float delayed_output(float indent)
outft = -1;
line_height = draw_systems(indent);
a2b("%s", tmpbuf);
free(tmpbuf);
return line_height;
}

Expand Down

0 comments on commit fd956e1

Please sign in to comment.