From 4e400fd3923c63e3b631cad7a99f0e8021038b04 Mon Sep 17 00:00:00 2001 From: gunboy001 Date: Fri, 1 Nov 2019 22:40:32 +0100 Subject: [PATCH] fixed segfault on opening files with large path --- Makefile | 2 +- ste.c | 11 +++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index bdc42ca..4ab4a06 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ CC=gcc CFLAGS=-Wall -Wextra -pedantic -Werror -Warray-bounds -OFLAGS=-O3 +OFLAGS=-O0 LFLAGS=-lncursesw #-ltcmalloc DFLAGS=-g -O0 -v -da -Q diff --git a/ste.c b/ste.c index 333383d..71dd46b 100644 --- a/ste.c +++ b/ste.c @@ -6,6 +6,7 @@ /* defines */ #define CTRL(k) ((k) & 0x1f) // Control mask modifier #define TABSIZE 4 // Tab size as used in render +#define STAT_SIZE 128 /* main data structure containing: * -cursor position @@ -31,7 +32,7 @@ struct term { int y; } dim; - char statusbar[30]; + char statusbar[STAT_SIZE]; int pad; } t; @@ -109,7 +110,8 @@ int main (int argc, char *argv[]) termInit(); /* Set the statusbar left (static) message */ - sprintf(t.statusbar, "%s : %s %d lines %dx%d", argv[0], argv[1], rows.rownum, t.dim.y, t.dim.x); + //caused 74e185d + snprintf(t.statusbar, STAT_SIZE, "%s %d lines %dx%d", argv[1], rows.rownum, t.dim.y, t.dim.x); /* remember the initial row number */ int irow = decimalSize(rows.rownum); @@ -262,6 +264,7 @@ void drawLines (void) lnMove(i, 0); /* Draw the line matcing render memory */ + if (&rows.rw[ln] == NULL) termDie("drawlines NULL"); if (rows.rw[ln].r_size > t.cur.off_x) { addnstr(&rows.rw[ln].render[t.cur.off_x], t.dim.x + 1); } @@ -343,7 +346,6 @@ void rowAddLast (char *s, int len) row *newr = reallocarray(rows.rw, rows.rownum + 1, sizeof(row)); if (newr == NULL) termDie("realloc in rowAddLast"); else rows.rw = newr; - //rows.rw = realloc(rows.rw, sizeof(row) * (rows.rownum + 1)); /* Allocate memory for the line and copy it * at the current row number */ @@ -483,7 +485,8 @@ void cursorMove (int a) t.cur.y++; t.cur.yy++; if (t.cur.off_x) t.cur.off_x = 0; - t.cur.x = rows.rw[t.cur.yy].size; + //t.cur.x = rows.rw[t.cur.yy].size; + t.cur.x = 0; } } else t.cur.x++; break;