Skip to content

Commit

Permalink
Fix some compiler and analysis tool warnings.
Browse files Browse the repository at this point in the history
  • Loading branch information
gwsw committed Apr 17, 2021
1 parent da495f5 commit df6e714
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 11 deletions.
2 changes: 1 addition & 1 deletion ch.c
Original file line number Diff line number Diff line change
Expand Up @@ -853,7 +853,7 @@ ch_init(f, flags)
* Allocate and initialize a new filestate.
*/
thisfile = (struct filestate *)
calloc(1, sizeof(struct filestate));
ecalloc(1, sizeof(struct filestate));
thisfile->buflist.next = thisfile->buflist.prev = END_OF_CHAIN;
thisfile->nbufs = 0;
thisfile->flags = flags;
Expand Down
2 changes: 1 addition & 1 deletion filename.c
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ homefile(filename)
/*
* Look for the file anywhere on search path.
*/
pathname = (char *) calloc(_MAX_PATH, sizeof(char));
pathname = (char *) ecalloc(_MAX_PATH, sizeof(char));
#if MSDOS_COMPILER==DJGPPC
{
char *res = searchpath(filename);
Expand Down
18 changes: 16 additions & 2 deletions lesskey.c
Original file line number Diff line number Diff line change
Expand Up @@ -115,14 +115,28 @@ lesskey_parse_error(s)
fprintf(stderr, "%s\n", s);
}

void *
ecalloc(count, size)
int count;
unsigned int size;
{
void *p;

p = calloc(count, size);
if (p != NULL)
return (p);
fprintf(stderr, "lesskey: cannot allocate %d bytes of memory\n", count*size);
exit(1);
}

static char *
mkpathname(dirname, filename)
char *dirname;
char *filename;
{
char *pathname;

pathname = calloc(strlen(dirname) + strlen(filename) + 2, sizeof(char));
pathname = ecalloc(strlen(dirname) + strlen(filename) + 2, sizeof(char));
strcpy(pathname, dirname);
strcat(pathname, PATHNAME_SEP);
strcat(pathname, filename);
Expand Down Expand Up @@ -284,7 +298,7 @@ main(argc, argv)
char *path = getenv("HOMEPATH");
if (drive != NULL && path != NULL)
{
char *env = (char *) calloc(strlen(drive) +
char *env = (char *) ecalloc(strlen(drive) +
strlen(path) + 6, sizeof(char));
strcpy(env, "HOME=");
strcat(env, drive);
Expand Down
5 changes: 3 additions & 2 deletions lesskey_parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

extern void lesskey_parse_error(char *msg);
extern char *homefile(char *filename);
extern void *ecalloc(int count, unsigned int size);

static int linenum;
static int errors;
Expand Down Expand Up @@ -131,7 +132,7 @@ xbuf_init(xbuf)
struct xbuffer *xbuf;
{
xbuf->size = 16;
xbuf->data = calloc(xbuf->size, sizeof(char));
xbuf->data = ecalloc(xbuf->size, sizeof(char));
xbuf->end = 0;
}

Expand All @@ -146,7 +147,7 @@ xbuf_add(xbuf, ch)
if (xbuf->end >= xbuf->size)
{
xbuf->size = xbuf->size * 2;
char *data = calloc(xbuf->size, sizeof(char));
char *data = ecalloc(xbuf->size, sizeof(char));
memcpy(data, xbuf->data, xbuf->end);
free(xbuf->data);
xbuf->data = data;
Expand Down
9 changes: 5 additions & 4 deletions optfunc.c
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ opt_j(type, s)
char *s;
{
PARG parg;
char buf[16];
char buf[24];
int len;
int err;

Expand Down Expand Up @@ -192,7 +192,7 @@ opt_j(type, s)
} else
{

sprintf(buf, ".%06ld", jump_sline_fraction);
SNPRINTF1(buf, sizeof(buf), ".%06ld", jump_sline_fraction);
len = (int) strlen(buf);
while (len > 2 && buf[len-1] == '0')
len--;
Expand Down Expand Up @@ -221,7 +221,7 @@ opt_shift(type, s)
char *s;
{
PARG parg;
char buf[16];
char buf[24];
int len;
int err;

Expand Down Expand Up @@ -257,7 +257,7 @@ opt_shift(type, s)
} else
{

sprintf(buf, ".%06ld", shift_count_fraction);
SNPRINTF1(buf, sizeof(buf), ".%06ld", shift_count_fraction);
len = (int) strlen(buf);
while (len > 2 && buf[len-1] == '0')
len--;
Expand All @@ -268,6 +268,7 @@ opt_shift(type, s)
break;
}
}

public void
calc_shift_count(VOID_PARAM)
{
Expand Down
2 changes: 1 addition & 1 deletion screen.c
Original file line number Diff line number Diff line change
Expand Up @@ -2519,7 +2519,7 @@ tput_fmt(fmt, color, f_putc)
int color;
int (*f_putc)(int);
{
char buf[16];
char buf[32];
if (color == attrcolor)
return;
SNPRINTF1(buf, sizeof(buf), fmt, color);
Expand Down

0 comments on commit df6e714

Please sign in to comment.