diff --git a/src/lib/internal.h b/src/lib/internal.h index c015f3eb3..738ded425 100644 --- a/src/lib/internal.h +++ b/src/lib/internal.h @@ -760,7 +760,9 @@ calc_gradient_channels(uint64_t* channels, uint64_t ul, uint64_t ur, void nclog(const char* fmt, ...); // logging -#define logerror(nc, fmt, ...) do{ if(nc->loglevel >= NCLOGLEVEL_ERROR){ nclog(__FILE__ ":%d:" fmt, __LINE__, ##__VA_ARGS__); } }while(0); +#define logerror(nc, fmt, ...) do{ \ + if((nc)->loglevel >= NCLOGLEVEL_ERROR){ \ + nclog("%s:%d:" fmt, __func__, __LINE__, ##__VA_ARGS__); } }while(0); #ifdef __cplusplus } diff --git a/src/lib/notcurses.c b/src/lib/notcurses.c index 4604c7996..4927070ab 100644 --- a/src/lib/notcurses.c +++ b/src/lib/notcurses.c @@ -2095,9 +2095,12 @@ uint32_t* ncplane_rgba(const ncplane* nc, ncblitter_e blit, char* ncplane_contents(const ncplane* nc, int begy, int begx, int leny, int lenx){ if(begy < 0 || begx < 0){ + logerror(nc->nc, "Beginning coordinates (%d/%d) below 0\n", begy, begx); return NULL; } if(begx >= nc->lenx || begy >= nc->leny){ + logerror(nc->nc, "Beginning coordinates (%d/%d) exceeded lengths (%d/%d)\n", + begy, begx, nc->leny, nc->lenx); return NULL; } if(lenx == -1){ // -1 means "to the end"; use all space available @@ -2107,9 +2110,12 @@ char* ncplane_contents(const ncplane* nc, int begy, int begx, int leny, int lenx leny = nc->leny - begy; } if(lenx < 0 || leny < 0){ // no need to draw zero-size object, exit + logerror(nc->nc, "Lengths (%d/%d) below 0\n", leny, lenx); return NULL; } if(begx + lenx > nc->lenx || begy + leny > nc->leny){ + logerror(nc->nc, "Ending coordinates (%d/%d) exceeded lengths (%d/%d)\n", + begy + leny, begx + lenx, nc->leny, nc->lenx); return NULL; } size_t retlen = 1;