summaryrefslogtreecommitdiff
path: root/mysys/my_vsnprintf.c
diff options
context:
space:
mode:
authorunknown <sasha@mysql.sashanet.com>2001-01-19 22:40:16 -0700
committerunknown <sasha@mysql.sashanet.com>2001-01-19 22:40:16 -0700
commitd2d369314239d34615f6a14963a5b11ab6100eac (patch)
tree1a867ce93f7bc873347f776d08ae6607a8ba554a /mysys/my_vsnprintf.c
parent5097c3f1ca7723930a92fcbb59158b7057afcb1d (diff)
downloadmariadb-git-d2d369314239d34615f6a14963a5b11ab6100eac.tar.gz
client/mysqltest.c
added send/reap/dirty_close include/mysql.h mysql_send_query()/mysql_reap_query() libmysql/libmysql.c mysql_send_query()/mysql_reap_query() mysys/my_vsnprintf.c fixed critical bug that codedumped when connection aborted sql/sql_parse.cc 0 mysql-test/r/dirty-close.result New BitKeeper file ``mysql-test/r/dirty-close.result'' mysql-test/t/dirty-close.test New BitKeeper file ``mysql-test/t/dirty-close.test'' client/mysqltest.c: added send/reap/dirty_close include/mysql.h: mysql_send_query()/mysql_reap_query() libmysql/libmysql.c: mysql_send_query()/mysql_reap_query() mysys/my_vsnprintf.c: fixed critical bug that codedumped when connection aborted sql/sql_parse.cc: 0
Diffstat (limited to 'mysys/my_vsnprintf.c')
-rw-r--r--mysys/my_vsnprintf.c39
1 files changed, 37 insertions, 2 deletions
diff --git a/mysys/my_vsnprintf.c b/mysys/my_vsnprintf.c
index ac89e3bcf1a..030846ea63b 100644
--- a/mysys/my_vsnprintf.c
+++ b/mysys/my_vsnprintf.c
@@ -24,7 +24,6 @@
int my_vsnprintf(char *to, size_t n, const char* fmt, va_list ap)
{
char *start=to, *end=to+n-1;
-
for (; *fmt ; fmt++)
{
if (fmt[0] != '%')
@@ -38,10 +37,14 @@ int my_vsnprintf(char *to, size_t n, const char* fmt, va_list ap)
fmt++;
while (isdigit(*fmt) || *fmt == '.' || *fmt == '-')
fmt++;
+ if(*fmt == 'l')
+ fmt++;
if (*fmt == 's') /* String parameter */
{
reg2 char *par = va_arg(ap, char *);
- uint plen = (uint) strlen(par);
+ uint plen;
+ if(!par) par = (char*)"(null)";
+ plen = (uint) strlen(par);
if ((uint) (end-to) > plen) /* Replace if possible */
{
to=strmov(to,par);
@@ -68,3 +71,35 @@ int my_vsnprintf(char *to, size_t n, const char* fmt, va_list ap)
*to='\0'; /* End of errmessage */
return (uint) (to - start);
}
+
+#ifdef MAIN
+static void my_printf(const char * fmt, ...)
+{
+ char buf[32];
+ int n;
+ va_list ar;
+ va_start(ar, fmt);
+ n = my_vsnprintf(buf, sizeof(buf),fmt, ar);
+ printf(buf);
+ printf("n=%d, strlen=%d\n", n, strlen(buf));
+ va_end(ar);
+}
+
+int main()
+{
+
+ my_printf("Hello\n");
+ my_printf("Hello int, %d\n", 1);
+ my_printf("Hello string '%s'\n", "I am a string");
+ my_printf("Hello hack hack hack hack hack hack hack %d\n", 1);
+ my_printf("Hello %d hack %d\n", 1, 4);
+ my_printf("Hello %d hack hack hack hack hack %d\n", 1, 4);
+ my_printf("Hello '%s' hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh\n", "hack");
+ my_printf("Hello hhhhhhhhhhhhhh %d sssssssssssssss\n", 1);
+ my_printf("Hello %u\n", 1);
+ my_printf("conn %ld to: '%-.64s' user: '%-.32s' host:\
+ `%-.64s' (%-.64s)", 1, 0,0,0,0);
+ return 0;
+}
+#endif
+