diff options
-rw-r--r-- | configure.ac | 2 | ||||
-rw-r--r-- | expr.c | 11 | ||||
-rw-r--r-- | geometry.c | 10 | ||||
-rw-r--r-- | listing.c | 10 | ||||
-rw-r--r-- | xkbcomp.c | 12 |
5 files changed, 35 insertions, 10 deletions
diff --git a/configure.ac b/configure.ac index b4c2d2c..90e6ff6 100644 --- a/configure.ac +++ b/configure.ac @@ -50,7 +50,7 @@ if test ! -f "$srcdir/xkbparse.c"; then fi fi -AC_CHECK_FUNCS([reallocarray recallocarray strdup strcasecmp]) +AC_CHECK_FUNCS([asprintf reallocarray recallocarray strdup strcasecmp]) # Checks for pkg-config packages PKG_CHECK_MODULES(XKBCOMP, [x11 xkbfile xproto >= 7.0.17]) @@ -762,13 +762,20 @@ ExprResolveString(ExprDef * expr, if (ExprResolveString(left, &leftRtrn, lookup, lookupPriv) && ExprResolveString(right, &rightRtrn, lookup, lookupPriv)) { - int len; char *new; - len = strlen(leftRtrn.str) + strlen(rightRtrn.str) + 1; + +#ifdef HAVE_ASPRINTF + if (asprintf(&new, "%s%s", leftRtrn.str, rightRtrn.str) < 0) + new = NULL; +#else + size_t len = strlen(leftRtrn.str) + strlen(rightRtrn.str) + 1; new = malloc(len); +#endif if (new) { +#ifndef HAVE_ASPRINTF snprintf(new, len, "%s%s", leftRtrn.str, rightRtrn.str); +#endif val_rtrn->str = new; return True; } @@ -3263,7 +3263,6 @@ FontFromParts(Atom fontTok, Atom slantTok, Atom setWidthTok, Atom varTok, int size, Atom encodingTok) { - int totalSize; const char *font, *weight, *slant, *setWidth, *variant, *encoding; char *rtrn; @@ -3282,7 +3281,13 @@ FontFromParts(Atom fontTok, None ? XkbAtomGetString(NULL, encodingTok) : DFLT_ENCODING); if (size == 0) size = DFLT_SIZE; - totalSize = + +#ifdef HAVE_ASPRINTF + if (asprintf(&rtrn, FONT_TEMPLATE, font, weight, slant, + setWidth, variant, size, encoding) < 0) + rtrn = NULL; +#else + size_t totalSize = strlen(FONT_TEMPLATE) + strlen(font) + strlen(weight) + strlen(slant); totalSize += strlen(setWidth) + strlen(variant) + strlen(encoding); rtrn = calloc(totalSize, 1); @@ -3291,6 +3296,7 @@ FontFromParts(Atom fontTok, snprintf(rtrn, totalSize, FONT_TEMPLATE, font, weight, slant, setWidth, variant, size, encoding); } +#endif return rtrn; } @@ -70,6 +70,7 @@ SOFTWARE. ******************************************************************/ +#include "utils.h" #include <stdio.h> #include <ctype.h> #include <sys/types.h> @@ -303,19 +304,24 @@ AddDirectory(char *head, char *ptrn, char *rest, char *map) { char *tmp, *filename; struct stat sbuf; - size_t tmpsize; filename = FileName(file); if (!filename || filename[0] == '.') continue; if (ptrn && (!XkbNameMatchesPattern(filename, ptrn))) continue; - tmpsize = (head ? strlen(head) : 0) + strlen(filename) + 2; +#ifdef HAVE_ASPRINTF + if (asprintf(&tmp, "%s%s%s", + (head ? head : ""), (head ? "/" : ""), filename) < 0) + continue; +#else + size_t tmpsize = (head ? strlen(head) : 0) + strlen(filename) + 2; tmp = malloc(tmpsize); if (!tmp) continue; snprintf(tmp, tmpsize, "%s%s%s", (head ? head : ""), (head ? "/" : ""), filename); +#endif if (stat(tmp, &sbuf) < 0) { free(tmp); @@ -24,6 +24,7 @@ ********************************************************/ +#include "utils.h" #include <stdio.h> #include <ctype.h> #include <X11/keysym.h> @@ -759,15 +760,20 @@ parseArgs(int argc, char *argv[]) } else if ((!outputFile) && (inputFile) && (strcmp(inputFile, "-") == 0)) { - int len = strlen("stdin") + strlen(fileTypeExt[outputFormat]) + 2; +#ifdef HAVE_ASPRINTF + if (asprintf(&outputFile, "stdin.%s", fileTypeExt[outputFormat]) < 0) +#else + size_t len = strlen("stdin") + strlen(fileTypeExt[outputFormat]) + 2; outputFile = calloc(len, sizeof(char)); - if (outputFile == NULL) + if (outputFile != NULL) + snprintf(outputFile, len, "stdin.%s", fileTypeExt[outputFormat]); + else +#endif { WSGO("Cannot allocate space for output file name\n"); ACTION("Exiting\n"); exit(1); } - snprintf(outputFile, len, "stdin.%s", fileTypeExt[outputFormat]); } else if ((outputFile == NULL) && (inputFile != NULL)) { |