diff --git a/include/mysql/service_my_snprintf.h b/include/mysql/service_my_snprintf.h index 21518d04258..210305078d0 100644 --- a/include/mysql/service_my_snprintf.h +++ b/include/mysql/service_my_snprintf.h @@ -67,21 +67,22 @@ bytes without terminating on any '\0's in the sequence. The default when it's unspecified is not defined. - Format 'uE' - treats the argument as an errno number. It prints this number, a space, - then its corresponding error message in double quotes. In other words: - printf("%uE", n) === printf("%d \"%sT\"", n, strerror(n)) - Format 'sT' replaces the end of the printed string with "..." if it was truncated. - Format 'sS' and 'uU' - are synonyms of 's' and 'u' respectively. They are escapes that avoid + Format 'sS' + is a synonym for 's'. It's an escape that avoid consuming the following plain char as one of the above extension suffixes. - Example: "Data size: %uUEiB" + Example: "Data Class: %sSType" + + Format 'iE' + treats the argument as an errno number. It prints this number, a space, + then its corresponding error message in double quotes. In other words: + printf("%iE", n) === printf("%i \"%sT\"", n, strerror(n)) + Format 'dE' has no effect. Therefore, to escape '%iE', use '%dE' instead. Unrecognized and multiple suffixes are not parsed; - for example, both "%sTQ" and "%uQ" will print a literal 'Q'. + for example, both "%sTQ" and "%iQ" will suffix with a literal 'Q'. */ #ifdef __cplusplus diff --git a/strings/my_vsnprintf.c b/strings/my_vsnprintf.c index 091c14ae1cd..cbf8b69ff72 100644 --- a/strings/my_vsnprintf.c +++ b/strings/my_vsnprintf.c @@ -586,16 +586,12 @@ start: /* Integer parameter */ longlong larg= args_arr[print_arr[i].arg_idx].longlong_arg; my_bool suffix_e= arg_type == 'M'; - if (arg_type == 'u') - switch (*print_arr[idx].begin) // look at the start of the next chunk - { - case 'E': - suffix_e= TRUE; - // fall-through - case 'U': // escape - ++print_arr[idx].begin; // roll forward to consume the char - break; - } + // look at the start of the next chunk + if (arg_type == 'i' && *print_arr[i].begin == 'E') + { + suffix_e= TRUE; + ++print_arr[i].begin; // roll forward to consume the char + } if (suffix_e) { const char *real_end; @@ -807,16 +803,11 @@ size_t my_vsnprintf_ex(CHARSET_INFO *cs, char *to, size_t n, larg= va_arg(ap, int); else larg= va_arg(ap, uint); - if (arg_type == 'u') - switch (fmt[1]) // look-ahead - { - case 'E': - suffix_e= TRUE; - // fall-through - case 'U': // escape - ++fmt; - break; - } + if (arg_type == 'i' && fmt[1] == 'E') // look-ahead + { + suffix_e= TRUE; + ++fmt; + } if (suffix_e) { const char *real_end= MY_MIN(to + width, end); diff --git a/unittest/mysys/my_vsnprintf-t.c b/unittest/mysys/my_vsnprintf-t.c index 078b0081cf6..c815a90c611 100644 --- a/unittest/mysys/my_vsnprintf-t.c +++ b/unittest/mysys/my_vsnprintf-t.c @@ -113,9 +113,6 @@ int main(void) test1("MariaDB extension escape sS works", "MariaDB extension escape sS %sS", "works"); - test1("MariaDB extension escape uU 2", - "MariaDB extension escape uU %uU", 2); - test1("MariaDB extension sQ works: `abcd` `op``q`", "MariaDB extension sQ works: %sQ %.4sQ", "abcd", "op`qrst"); @@ -131,21 +128,24 @@ int main(void) } { - // Test that %uE works + // Test that %iE works const char *results[]= { - "MariaDB extension uE works: 1 \"Operation not permitted\"", // Linux - "MariaDB extension uE works: 1 \"Not owner\"", // Solaris + "MariaDB extension iE works: 1 \"Operation not permitted\"", // Linux + "MariaDB extension iE works: 1 \"Not owner\"", // Solaris NullS }; - test_many(results, "MariaDB extension uE works: %uE", 1); + test_many(results, "MariaDB extension iE works: %iE", 1); } - test1("uE with 0 errno: 0 \"Internal error/check (Not system error)\"", - "uE with 0 errno: %uE", 0); - test1("uE with width: <0 \"Internal error...>", - "uE with width: <%.20uE>", 0); - test_w_len("uE with small buf: 0 \"..", - 25, "uE with small buf: %uE", 0); + test1("iE with 0 errno: 0 \"Internal error/check (Not system error)\"", + "iE with 0 errno: %iE", 0); + test1("iE with width: <0 \"Internal error...>", + "iE with width: <%.20iE>", 0); + test_w_len("iE with small buf: 0 \"..", + 25, "iE with small buf: %iE", 0); + + test1("MariaDB extension dE DOESN'T work: 0E", + "MariaDB extension dE DOESN'T work: %dE", 0); test1("MariaDB extension sT works: ", "MariaDB extension sT %sT: <%.5sT> <%.5sT>", "works", "abcd", "opqrst");