From 81e46cab5f4bdd69fa0a644dba86f6902cece175 Mon Sep 17 00:00:00 2001 From: Alan Coopersmith Date: Sat, 10 Dec 2022 16:10:01 -0800 Subject: Use asprintf() if the platform supports it Signed-off-by: Alan Coopersmith --- geometry.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'geometry.c') diff --git a/geometry.c b/geometry.c index bce1723..50df5eb 100644 --- a/geometry.c +++ b/geometry.c @@ -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; } -- cgit v1.2.3