Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cpp.ansi, em_m2: fix crash (signal 11) on macOS. #316

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 21 additions & 8 deletions lang/cem/cpp.ansi/preprocess.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
#include <stdio.h>
#include <system.h>
#include <alloc.h>
#include <limits.h>
#include <string.h>
#include "preprocess.h"
#include "input.h"
#include "parameters.h"
Expand All @@ -22,15 +24,14 @@
#include "error.h"
#include "bits.h"
#include "skip.h"
#include "print.h"

char _obuf[OBUFSIZE];
#ifdef DOBITS
char bits[128];
#endif
extern int InputLevel;

extern char* sprint();

void Xflush(void)
{
sys_write(STDOUT, _obuf, OBUFSIZE);
Expand Down Expand Up @@ -126,7 +127,22 @@ void do_pragma(void)
LineNumber++;
}

char Xbuf[256];
char *Xbuf = NULL;
size_t Xbufsize = 0;

static char *line_directive(unsigned int lineno)
{
size_t needsize = sizeof(LINE_PREFIX " - \"\"\n") + (sizeof(int) * CHAR_BIT + 2) / 3 + strlen(FileName);
if (Xbufsize < needsize)
{
if (Xbuf)
free(Xbuf);
Xbuf = Malloc(needsize);
Xbufsize = needsize;
}
sprint(Xbuf, "%s %d \"%s\"\n", LINE_PREFIX, (int)lineno, FileName);
return Xbuf;
}

void preprocess(char *fn)
{
Expand Down Expand Up @@ -156,9 +172,7 @@ void preprocess(char *fn)
/* Generate a line directive communicating the
source filename
*/
register char* p = Xbuf;

sprint(p, "%s 1 \"%s\"\n", LINE_PREFIX, FileName);
register char* p = line_directive(1);
while (*p)
{
echo(*p++);
Expand All @@ -172,8 +186,7 @@ void preprocess(char *fn)
lineno = LineNumber; \
if (!options['P']) \
{ \
register char* p = Xbuf; \
sprint(Xbuf, "%s %d \"%s\"\n", LINE_PREFIX, (int)LineNumber, FileName); \
register char* p = line_directive(LineNumber); \
op--; \
while (op >= _obuf && (class(*op) == STSKIP || *op == '\n')) \
op--; \
Expand Down
1 change: 0 additions & 1 deletion lang/m2/comp/enter.c
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@ void EnterVarList(struct node *Idlist, struct type *type, int local)
register struct node *idlist = Idlist;
register struct scopelist *sc = CurrVis;
char buf[256];
extern char *sprint();

if (local) {
/* Find the closest enclosing open scope. This
Expand Down
2 changes: 2 additions & 0 deletions lang/m2/comp/f_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

/* $Id$ */

#include "print.h"

struct f_info {
unsigned short f_lineno;
char *f_filename;
Expand Down
1 change: 0 additions & 1 deletion lang/m2/comp/misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ struct idf *gen_anon_idf(void)
*/
static int name_cnt;
char *s = Malloc(strlen(FileName)+50);
char *sprint();

sprint(s, "#%d in %s, line %u",
++name_cnt, FileName, LineNumber);
Expand Down
1 change: 0 additions & 1 deletion lang/m2/comp/program.g
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,6 @@ DefinitionModule
int dummy;
extern struct idf *DefId;
extern int ForeignFlag;
extern char *sprint();
register struct scope *currscope = CurrentScope;
char buf[512];
} :
Expand Down
2 changes: 1 addition & 1 deletion lang/m2/comp/stab.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@
#include "error.h"
#include "stab.h"
#include "main.h"
#include "print.h"

extern int gdb_flag;

#define INCR_SIZE 64

extern int proclevel;
extern char *sprint();

static struct db_str {
unsigned sz;
Expand Down
2 changes: 2 additions & 0 deletions lang/m2/m2mm/f_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

/* $Id$ */

#include "print.h"

struct f_info {
unsigned short f_lineno;
char *f_fn;
Expand Down
1 change: 0 additions & 1 deletion lang/m2/m2mm/misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ gen_anon_idf()
*/
static int name_cnt;
char buff[100];
char *sprint();

sprint(buff, "#%d in %s, line %u",
++name_cnt, FileName, LineNumber);
Expand Down
Loading