summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlan Coopersmith <alan.coopersmith@oracle.com>2011-02-10 22:53:46 -0800
committerAlan Coopersmith <alan.coopersmith@oracle.com>2011-02-13 09:12:57 -0800
commitae3cfee9bd393d28159072a67360de57e64f48cd (patch)
tree7282ea5d056485a115c6aafe85ec8a68abb84bcc
parentfce78beab4b5f7ee99bf66d35c36b7ed12871d5a (diff)
Use snprintf instead of trying to pre-measure sprintf result sizes.
Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com> Reviewed-by: Dirk Wallenstein <halsmit@t-online.de>
-rw-r--r--setxkbmap.c7
1 files changed, 3 insertions, 4 deletions
diff --git a/setxkbmap.c b/setxkbmap.c
index 1590fdd..75c3864 100644
--- a/setxkbmap.c
+++ b/setxkbmap.c
@@ -625,14 +625,13 @@ findFileInPath(char *name, char *subdir)
}
for (i = 0; (i < numInclPath); i++)
{
- if ((strlen(inclPath[i]) + strlen(subdir) + strlen(name) + 2) >
+ if (snprintf(buf, PATH_MAX, "%s/%s%s", inclPath[i], subdir, name) >=
PATH_MAX)
{
VMSG3(0, "Path too long (%s/%s%s). Ignored.\n", inclPath[i],
subdir, name);
continue;
}
- sprintf(buf, "%s/%s%s", inclPath[i], subdir, name);
fp = fopen(name, "r");
if ((verbose > 7) || ((!fp) && (verbose > 5)))
MSG2("%s file %s\n", (fp ? "Found" : "Didn't find"), buf);
@@ -844,13 +843,13 @@ applyRules(void)
* we succeed with */
for (i = 0; (i < numInclPath) && (!rules); i++)
{
- if ((strlen(inclPath[i]) + strlen(rfName) + 8) > PATH_MAX)
+ if (snprintf(buf, PATH_MAX, "%s/rules/%s",
+ inclPath[i], rfName) >= PATH_MAX)
{
VMSG2(0, "Path too long (%s/rules/%s). Ignored.\n",
inclPath[i], rfName);
continue;
}
- sprintf(buf, "%s/rules/%s", inclPath[i], rfName);
rules = XkbRF_Load(buf, svValue[LOCALE_NDX], True, True);
}
}