Fix some warnings about strcpy() etc. on OpenBSD
This commit is contained in:
parent
7d4d519a51
commit
582511d57b
5
ls.c
5
ls.c
|
@ -112,6 +112,7 @@ lsdir(const char *path)
|
||||||
struct dirent *d;
|
struct dirent *d;
|
||||||
DIR *dp;
|
DIR *dp;
|
||||||
Entry ent, *ents = NULL;
|
Entry ent, *ents = NULL;
|
||||||
|
size_t sz;
|
||||||
|
|
||||||
cwd = agetcwd();
|
cwd = agetcwd();
|
||||||
if(!(dp = opendir(path)))
|
if(!(dp = opendir(path)))
|
||||||
|
@ -135,9 +136,9 @@ lsdir(const char *path)
|
||||||
} else {
|
} else {
|
||||||
if(!(ents = realloc(ents, ++n * sizeof *ents)))
|
if(!(ents = realloc(ents, ++n * sizeof *ents)))
|
||||||
eprintf("realloc:");
|
eprintf("realloc:");
|
||||||
if(!(p = malloc(strlen(d->d_name)+1)))
|
if(!(p = malloc((sz = strlen(d->d_name)+1))))
|
||||||
eprintf("malloc:");
|
eprintf("malloc:");
|
||||||
strcpy(p, d->d_name);
|
memcpy(p, d->d_name, sz);
|
||||||
mkent(&ents[n-1], p, tflag || lflag);
|
mkent(&ents[n-1], p, tflag || lflag);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,8 @@ afgets(char **p, size_t *size, FILE *fp)
|
||||||
if(len+1 > *size && !(*p = realloc(*p, len+1)))
|
if(len+1 > *size && !(*p = realloc(*p, len+1)))
|
||||||
eprintf("realloc:");
|
eprintf("realloc:");
|
||||||
|
|
||||||
strcpy(&(*p)[len-n], buf);
|
memcpy(&(*p)[len-n], buf, n);
|
||||||
|
(*p)[len] = '\0';
|
||||||
|
|
||||||
if(buf[n-1] == '\n' || feof(fp))
|
if(buf[n-1] == '\n' || feof(fp))
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -11,6 +11,7 @@ getlines(FILE *fp, struct linebuf *b)
|
||||||
{
|
{
|
||||||
char *line = NULL, **nline;
|
char *line = NULL, **nline;
|
||||||
size_t size = 0;
|
size_t size = 0;
|
||||||
|
size_t linelen;
|
||||||
|
|
||||||
while(afgets(&line, &size, fp)) {
|
while(afgets(&line, &size, fp)) {
|
||||||
if(++b->nlines > b->capacity) {
|
if(++b->nlines > b->capacity) {
|
||||||
|
@ -20,9 +21,9 @@ getlines(FILE *fp, struct linebuf *b)
|
||||||
eprintf("realloc:");
|
eprintf("realloc:");
|
||||||
b->lines = nline;
|
b->lines = nline;
|
||||||
}
|
}
|
||||||
if(!(b->lines[b->nlines-1] = malloc(strlen(line)+1)))
|
if(!(b->lines[b->nlines-1] = malloc((linelen = strlen(line)+1))))
|
||||||
eprintf("malloc:");
|
eprintf("malloc:");
|
||||||
strcpy(b->lines[b->nlines-1], line);
|
memcpy(b->lines[b->nlines-1], line, linelen);
|
||||||
}
|
}
|
||||||
free(line);
|
free(line);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user