Skip to content

Commit

Permalink
Buffer review.
Browse files Browse the repository at this point in the history
  • Loading branch information
gwsw committed Oct 1, 2021
1 parent d54eea3 commit 1d95a13
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 10 deletions.
4 changes: 2 additions & 2 deletions charset.c
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ prchar(c)
LWCHAR c;
{
/* {{ This buffer can be overrun if LESSBINFMT is a long string. }} */
static char buf[32];
static char buf[MAX_PRCHAR_LEN+1];

c &= 0377;
if ((c < 128 || !utf_mode) && !control_char(c))
Expand Down Expand Up @@ -480,7 +480,7 @@ prchar(c)
prutfchar(ch)
LWCHAR ch;
{
static char buf[32];
static char buf[MAX_PRCHAR_LEN+1];

if (ch == ESC)
strcpy(buf, "ESC");
Expand Down
1 change: 1 addition & 0 deletions less.h
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ typedef off_t LINENUM;
#define MAX_LINENUM_WIDTH 16 /* Max width of a line number */
#define MAX_STATUSCOL_WIDTH 4 /* Max width of the status column */
#define MAX_UTF_CHAR_LEN 6 /* Max bytes in one UTF-8 char */
#define MAX_PRCHAR_LEN 31 /* Max chars in prchar() result */

#define NULL_POSITION ((POSITION)(-1))

Expand Down
8 changes: 5 additions & 3 deletions lesskey_parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,8 @@ init_tables(tables)
xbuf_init(&tables->vartable.buf);
}

#define CHAR_STRING_LEN 8

static char *
char_string(buf, ch)
char *buf;
Expand All @@ -171,7 +173,7 @@ char_string(buf, ch)
buf[1] = '\0';
} else
{
snprintf(buf, 5, "\\x%02x", ch);
snprintf(buf, CHAR_STRING_LEN, "\\x%02x", ch);
}
return buf;
}
Expand All @@ -187,7 +189,7 @@ tstr(pp, xlate)
char *p;
char ch;
int i;
static char buf[10];
static char buf[CHAR_STRING_LEN];
static char tstr_control_k[] =
{ SK_SPECIAL_KEY, SK_CONTROL_K, 6, 1, 1, 1, '\0' };

Expand Down Expand Up @@ -399,7 +401,7 @@ version_line(s, tables)
char op;
int ver;
char *e;
char buf[8];
char buf[CHAR_STRING_LEN];

s += strlen("#version");
s = skipsp(s);
Expand Down
2 changes: 1 addition & 1 deletion option.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ opt_desc(o)
propt(c)
int c;
{
static char buf[8];
static char buf[MAX_PRCHAR_LEN+2];

sprintf(buf, "-%s", prchar(c));
return (buf);
Expand Down
2 changes: 1 addition & 1 deletion os.c
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ get_time(VOID_PARAM)
strerror(err)
int err;
{
static char buf[16];
static char buf[INT_STRLEN_BOUND(int)+12];
#if HAVE_SYS_ERRLIST
extern char *sys_errlist[];
extern int sys_nerr;
Expand Down
4 changes: 2 additions & 2 deletions screen.c
Original file line number Diff line number Diff line change
Expand Up @@ -2547,7 +2547,7 @@ tput_fmt(fmt, color, f_putc)
int color;
int (*f_putc)(int);
{
char buf[32];
char buf[INT_STRLEN_BOUND(int)+16];
if (color == attrcolor)
return;
SNPRINTF1(buf, sizeof(buf), fmt, color);
Expand Down Expand Up @@ -2628,7 +2628,7 @@ WIN32put_fmt(fmt, color)
char *fmt;
int color;
{
char buf[16];
char buf[INT_STRLEN_BOUND(int)+16];
int len = SNPRINTF1(buf, sizeof(buf), fmt, color);
WIN32textout(buf, len);
return TRUE;
Expand Down
2 changes: 1 addition & 1 deletion tags.c
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,7 @@ findgtag(tag, type)
char *tag; /* tag to load */
int type; /* tags type */
{
char buf[256];
char buf[1024];
FILE *fp;
struct tag *tp;

Expand Down

0 comments on commit 1d95a13

Please sign in to comment.