[PATCH] Fix warnings about strcpy() etc. on OpenBSD

From: sin <sin_AT_2f30.org>
Date: Thu, 15 Aug 2013 10:25:29 +0100

---
 ls.c            | 2 +-
 split.c         | 2 +-
 util/afgets.c   | 2 +-
 util/getlines.c | 2 +-
 4 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/ls.c b/ls.c
index f61d7c5..cd6cfe8 100644
--- a/ls.c
+++ b/ls.c
_AT_@ -137,7 +137,7 @@ lsdir(const char *path)
 				eprintf("realloc:");
 			if(!(p = malloc(strlen(d->d_name)+1)))
 				eprintf("malloc:");
-			strcpy(p, d->d_name);
+			snprintf(p, strlen(d->d_name)+1, "%s", d->d_name);
 			mkent(&ents[n-1], p, tflag || lflag);
 		}
 	}
diff --git a/split.c b/split.c
index cf22125..633c02e 100644
--- a/split.c
+++ b/split.c
_AT_@ -74,7 +74,7 @@ main(int argc, char **argv)
 	plen = strlen(prefix);
 	if(plen+slen > NAME_MAX)
 		eprintf("split: names cannot exceed %d bytes", NAME_MAX);
-	strcpy(name, prefix);
+	snprintf(name, sizeof(name), "%s", prefix);
 
 	if(file && strcmp(file, "-") != 0) {
 		in = fopen(file, "r");
diff --git a/util/afgets.c b/util/afgets.c
index e1d719d..836b7a5 100644
--- a/util/afgets.c
+++ b/util/afgets.c
_AT_@ -17,7 +17,7 @@ afgets(char **p, size_t *size, FILE *fp)
 		if(len+1 > *size && !(*p = realloc(*p, len+1)))
 			eprintf("realloc:");
 
-		strcpy(&(*p)[len-n], buf);
+		snprintf(&(*p)[len-n], n+1, "%s", buf);
 
 		if(buf[n-1] == '\n' || feof(fp))
 			break;
diff --git a/util/getlines.c b/util/getlines.c
index d3152ec..c5b4b71 100644
--- a/util/getlines.c
+++ b/util/getlines.c
_AT_@ -22,7 +22,7 @@ getlines(FILE *fp, struct linebuf *b)
 		}
 		if(!(b->lines[b->nlines-1] = malloc(strlen(line)+1)))
 			eprintf("malloc:");
-		strcpy(b->lines[b->nlines-1], line);
+		snprintf(b->lines[b->nlines-1], strlen(line)+1, "%s", line);
 	}
 	free(line);
 }
-- 
1.8.2.3
--jRHKVT23PllUwdXP--
Received on Mon Sep 17 2001 - 00:00:00 CEST

This archive was generated by hypermail 2.3.0 : Thu Aug 15 2013 - 11:48:03 CEST