Skip to content

Bug Fix:Integer Overflow #14

Merged
merged 4 commits into from
Jan 24, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ xwin.o: xwin.c

xdu.o: xdu.c

.PHONY: clean, nice
clean:
rm -f xdu xdu.o xwin.o

.PHONY: nice
nice:
indent -kr -l0 --no-tabs $(SRCS)
clang-format -i -style=webkit $(SRCS)
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ This release was tested against MarIuX.

## Revision History

### Version 3.0p9 - Sep 13 2018
- fix segmentation fault
- Niclas Hofmann, `niclas@molgen.mpg.de`

### Version 3.0p8 - Sep 3 2018
- change and add mouse control
- Niclas Hofmann, `niclas@molgen.mpg.de`
Expand Down
17 changes: 8 additions & 9 deletions xdu.c
Original file line number Diff line number Diff line change
Expand Up @@ -970,7 +970,7 @@ void fprintpsbox(FILE* fp, int x1, int y1, int x2, int y2)
" 10 setmiterlimit\n"
" gsave\n"
" newpath\n"
" %i %i moveto %i %i lineto %i %i lineto %i %i lineto\n"
" %d %d moveto %d %d lineto %d %d lineto %d %d lineto\n"
" closepath\n"
" stroke\n"
" grestore\n"
Expand All @@ -994,11 +994,10 @@ void fprintpstext(FILE* fp, int x, int y, char* s)

void savepschildren(FILE* fp, struct node* nodep, struct rect rect, int showsize)
{
long long totalsize;
long long size, totalsize;
int totalheight,
height,
top,
size;
top;
struct node* np;
char *name,
label[1024];
Expand Down Expand Up @@ -1060,7 +1059,7 @@ void savepschildren(FILE* fp, struct node* nodep, struct rect rect, int showsize
savepschildren(fp, np, subrect, showsize);

size += np->size;
top = rect.top + (totalsize ? (double)size / (double)totalsize * rect.height + 0.5 : 0);
top = rect.top + (int)(totalsize ? (double)size / (double)totalsize * rect.height + 0.5 : 0);
}
}

Expand Down Expand Up @@ -1129,9 +1128,9 @@ void savetops(char* fname, int showsize)
}
}

void fprintsvgstart(FILE* fp)
void fprintsvgstart(FILE* fp, int width, int height)
{
fprintf(fp, "<svg xmlns=\"http://www.w3.org/2000/svg\">\n");
fprintf(fp, "<?xml version=\"1.0\"?>\n<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"%d\" height=\"%d\">\n", width, height);
}

void fprintsvgend(FILE* fp)
Expand Down Expand Up @@ -1202,12 +1201,12 @@ void savesvgnode(FILE* fp, struct node* nodep, int showsize, int depth)
}
}

void savetosvg(char* fname, int showsize)
void savetosvg(char* fname, int showsize, int width, int height)
{
FILE* fp;

if ((fp = fopen(fname, "w")) != NULL) {
fprintsvgstart(fp);
fprintsvgstart(fp, width, height);
savesvgnode(fp, topp, showsize, 0);
fprintsvgend(fp);
fclose(fp);
Expand Down
70 changes: 37 additions & 33 deletions xwin.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ extern int nodeinfo();
extern int helpinfo();
extern int ncols;
extern void savetops(char*, int);
extern void savetosvg(char*, int);
extern void savetosvg(char*, int, int, int);

/*
* EXPORTS: routines that this module exports outside
Expand Down Expand Up @@ -206,8 +206,9 @@ static char defaultTranslations[] = "\

#define ALL_UNUSED_IMPL_(nargs) UNUSED##nargs
#define ALL_UNUSED_IMPL(nargs) ALL_UNUSED_IMPL_(nargs)
#define UNUSED(...) ALL_UNUSED_IMPL(VA_NUM_ARGS(__VA_ARGS__)) \
(__VA_ARGS__)
#define UNUSED(...) \
ALL_UNUSED_IMPL(VA_NUM_ARGS(__VA_ARGS__)) \
(__VA_ARGS__)

/*
* action routines
Expand Down Expand Up @@ -272,36 +273,6 @@ a_saveps(Widget w, XEvent* e, String* params, Cardinal* num_params)
fprintf(stderr, "saved !\n");
}

static void
a_savesvg(Widget w, XEvent* e, String* params, Cardinal* num_params)
{
char* extension = ".svg";
int len = strlen(res.svgfilename) + 3 + strlen(extension) + 1;
char tmp[len];
char* fname;
int i;

UNUSED(w, e, params, num_params);

for (i = 0; i > -1; ++i) {
snprintf(tmp, len, "%s-%02d%s", res.svgfilename, i, extension);
if (access(tmp, F_OK) == -1) {
fname = tmp;
break;
}
}

if (i < 0) {
fprintf(stderr, "ERROR: there are too many xdu_output files!!!\n");
exit(1);
}

fprintf(stderr, "saving as scalable vector graphic to file: %s ..",
fname);
savetosvg(fname, res.showsize);
fprintf(stderr, "saved !\n");
}

static void
a_up(Widget w, XEvent* e, String* params, Cardinal* num_params)
{
Expand Down Expand Up @@ -393,6 +364,39 @@ static Window win;
static GC gc;
static XtAppContext app_con;

static void
a_savesvg(Widget w, XEvent* e, String* params, Cardinal* num_params)
{
char* extension = ".svg";
int len = strlen(res.svgfilename) + 3 + strlen(extension) + 1;
char tmp[len];
char* fname;
int i;
XWindowAttributes xwa;

XGetWindowAttributes(dpy, win, &xwa);

UNUSED(w, e, params, num_params);

for (i = 0; i > -1; ++i) {
snprintf(tmp, len, "%s-%02d%s", res.svgfilename, i, extension);
if (access(tmp, F_OK) == -1) {
fname = tmp;
break;
}
}

if (i < 0) {
fprintf(stderr, "ERROR: there are too many xdu_output files!!!\n");
exit(1);
}

fprintf(stderr, "saving as scalable vector graphic to file: %s ..",
fname);
savetosvg(fname, res.showsize, xwa.width, xwa.height);
fprintf(stderr, "saved !\n");
}

Widget toplevel;

/*
Expand Down