[PATCH:makedepend 4/4] Convert more sprintf calls to snprintf
Alan Coopersmith
alan.coopersmith at oracle.com
Sun Jan 6 13:04:01 PST 2013
Signed-off-by: Alan Coopersmith <alan.coopersmith at oracle.com>
---
cppsetup.c | 2 +-
include.c | 4 ++--
main.c | 2 +-
pr.c | 4 ++--
4 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/cppsetup.c b/cppsetup.c
index ab00069..58e2a12 100644
--- a/cppsetup.c
+++ b/cppsetup.c
@@ -45,7 +45,7 @@ my_if_errors (IfParser *ip, const char *cp, const char *expecting)
int prefixlen;
int i;
- sprintf (prefix, "\"%s\":%d", filename, lineno);
+ snprintf (prefix, sizeof(prefix), "\"%s\":%d", filename, lineno);
prefixlen = strlen(prefix);
fprintf (stderr, "%s: %s", prefix, pd->line);
i = cp - pd->line;
diff --git a/include.c b/include.c
index 8eb6a52..159dfc7 100644
--- a/include.c
+++ b/include.c
@@ -50,7 +50,7 @@ issymbolic(const char *dir, const char *component)
struct stat st;
char buf[ BUFSIZ ], **pp;
- sprintf(buf, "%s%s%s", dir, *dir ? "/" : "", component);
+ snprintf(buf, sizeof(buf), "%s%s%s", dir, *dir ? "/" : "", component);
for (pp=notdotdot; *pp; pp++)
if (strcmp(*pp, buf) == 0)
return (TRUE);
@@ -292,7 +292,7 @@ inc_path(const char *file, const char *include, int type)
pp = includedirsnext;
for (; *pp; pp++) {
- sprintf(path, "%s/%s", *pp, include);
+ snprintf(path, sizeof(path), "%s/%s", *pp, include);
remove_dotdot(path);
if (stat(path, &st) == 0 && !S_ISDIR(st.st_mode)) {
includedirsnext = pp + 1;
diff --git a/main.c b/main.c
index 12efb46..2db9ec6 100644
--- a/main.c
+++ b/main.c
@@ -743,7 +743,7 @@ redirect(const char *line, const char *makefile)
stat(makefile, &st);
if ((fdin = fopen(makefile, "r")) == NULL)
fatalerr("cannot open \"%s\"\n", makefile);
- sprintf(backup, "%s.bak", makefile);
+ snprintf(backup, sizeof(backup), "%s.bak", makefile);
unlink(backup);
#if defined(WIN32) || defined(__CYGWIN__)
fclose(fdin);
diff --git a/pr.c b/pr.c
index 9c39a16..04abef9 100644
--- a/pr.c
+++ b/pr.c
@@ -75,8 +75,8 @@ pr(struct inclist *ip, const char *file, const char *base)
len = strlen(ip->i_file)+1;
if (current_len + len > width || file != lastfile) {
lastfile = file;
- sprintf(buf, "\n%s%s%s: %s", objprefix, base, objsuffix,
- ip->i_file);
+ snprintf(buf, sizeof(buf), "\n%s%s%s: %s",
+ objprefix, base, objsuffix, ip->i_file);
len = current_len = strlen(buf);
}
else {
--
1.7.9.2
More information about the xorg-devel
mailing list