summaryrefslogtreecommitdiff
path: root/strings
diff options
context:
space:
mode:
authorMichael Widenius <monty@askmonty.org>2012-09-01 00:54:54 +0300
committerMichael Widenius <monty@askmonty.org>2012-09-01 00:54:54 +0300
commit1999be8d4e9d721243c51b04c76ba11ad1e9fa56 (patch)
treecd287f49c709f844d10d774643feb5843acf99a6 /strings
parent5a86a61219826aadf8d08cbc447fe438f2bf50c3 (diff)
parentb45c551ee32d0d5260f4958abf93efab1a4614a2 (diff)
downloadmariadb-git-1999be8d4e9d721243c51b04c76ba11ad1e9fa56.tar.gz
Automatic merge with 5.5
Diffstat (limited to 'strings')
-rw-r--r--strings/ctype-ucs2.c11
-rw-r--r--strings/my_vsnprintf.c49
2 files changed, 55 insertions, 5 deletions
diff --git a/strings/ctype-ucs2.c b/strings/ctype-ucs2.c
index f4ae1306c2e..52eaece5528 100644
--- a/strings/ctype-ucs2.c
+++ b/strings/ctype-ucs2.c
@@ -2317,13 +2317,18 @@ void my_fill_utf32(CHARSET_INFO *cs,
char *s, size_t slen, int fill)
{
char buf[10];
- uint __attribute__((unused)) buflen;
+#ifndef DBUG_OFF
+ uint buflen;
+#endif
char *e= s + slen;
DBUG_ASSERT((slen % 4) == 0);
- buflen= cs->cset->wc_mb(cs, (my_wc_t) fill, (uchar*) buf,
- (uchar*) buf + sizeof(buf));
+#ifndef DBUG_OFF
+ buflen=
+#endif
+ cs->cset->wc_mb(cs, (my_wc_t) fill, (uchar*) buf,
+ (uchar*) buf + sizeof(buf));
DBUG_ASSERT(buflen == 4);
while (s < e)
{
diff --git a/strings/my_vsnprintf.c b/strings/my_vsnprintf.c
index 7ef0ebf7a12..ccd58bcf8f7 100644
--- a/strings/my_vsnprintf.c
+++ b/strings/my_vsnprintf.c
@@ -730,8 +730,53 @@ size_t my_snprintf(char* to, size_t n, const char* fmt, ...)
int my_vfprintf(FILE *stream, const char* format, va_list args)
{
char cvtbuf[1024];
- (void) my_vsnprintf(cvtbuf, sizeof(cvtbuf), format, args);
- return fprintf(stream, "%s\n", cvtbuf);
+ int alloc= 0;
+ char *p= cvtbuf;
+ size_t cur_len= sizeof(cvtbuf);
+ int ret;
+
+ /*
+ We do not know how much buffer we need.
+ So start with a reasonably-sized stack-allocated buffer, and increase
+ it exponentially until it is big enough.
+ */
+ for (;;)
+ {
+ size_t new_len;
+ size_t actual= my_vsnprintf(p, cur_len, format, args);
+ if (actual < cur_len - 1)
+ break;
+ /*
+ Not enough space (or just enough with nothing to spare - but we cannot
+ distinguish this case from the return value). Allocate a bigger buffer
+ and try again.
+ */
+ if (alloc)
+ (*my_str_free)(p);
+ else
+ alloc= 1;
+ new_len= cur_len*2;
+ if (new_len < cur_len)
+ return 0; /* Overflow */
+ cur_len= new_len;
+ p= (*my_str_malloc)(cur_len);
+ if (!p)
+ return 0;
+ }
+ ret= fprintf(stream, "%s", p);
+ if (alloc)
+ (*my_str_free)(p);
+ return ret;
+}
+
+int my_fprintf(FILE *stream, const char* format, ...)
+{
+ int result;
+ va_list args;
+ va_start(args, format);
+ result= my_vfprintf(stream, format, args);
+ va_end(args);
+ return result;
}