The printf builtin modifies the user's format strings
by prefixing integer conversion specifications with the
'j' (intmax_t) length modifier.  Since this is not portable,
instead prefix them with the length modifier extracted from
the PRIdMAX constant.

Signed-off-by: Brian Koropoff <bkorop...@gmail.com>
---
 src/bltin/printf.c |   15 ++++++++-------
 1 files changed, 8 insertions(+), 7 deletions(-)

diff --git a/src/bltin/printf.c b/src/bltin/printf.c
index b0c3774..4ac2ee8 100644
--- a/src/bltin/printf.c
+++ b/src/bltin/printf.c
@@ -317,15 +317,16 @@ static char *
 mklong(const char *str, const char *ch)
 {
        char *copy;
-       size_t len;     
+       size_t len;
+       size_t pridmax_len = strlen(PRIdMAX);
 
-       len = ch - str + 3;
+       len = ch - str + pridmax_len;
        STARTSTACKSTR(copy);
-       copy = makestrspace(len, copy);
-       memcpy(copy, str, len - 3);
-       copy[len - 3] = 'j';
-       copy[len - 2] = *ch;
-       copy[len - 1] = '\0';
+       copy = makestrspace(len + 1, copy);
+       memcpy(copy, str, len - pridmax_len);
+       memcpy(copy + len - pridmax_len, PRIdMAX, pridmax_len - 1);
+       copy[len - 1] = *ch;
+       copy[len] = '\0';
        return (copy);  
 }
 
-- 
1.7.1


--
To unsubscribe from this list: send the line "unsubscribe dash" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to