summaryrefslogtreecommitdiffstats
path: root/src/lib/stdio.C
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/stdio.C')
-rw-r--r--src/lib/stdio.C30
1 files changed, 24 insertions, 6 deletions
diff --git a/src/lib/stdio.C b/src/lib/stdio.C
index d61b48cf9..9ed438f78 100644
--- a/src/lib/stdio.C
+++ b/src/lib/stdio.C
@@ -5,7 +5,9 @@
/* */
/* OpenPOWER HostBoot Project */
/* */
-/* COPYRIGHT International Business Machines Corp. 2011,2014 */
+/* Contributors Listed Below - COPYRIGHT 2011,2019 */
+/* [+] International Business Machines Corp. */
+/* */
/* */
/* Licensed under the Apache License, Version 2.0 (the "License"); */
/* you may not use this file except in compliance with the License. */
@@ -31,7 +33,10 @@ class SprintfBuffer : public Util::ConsoleBufferInterface
{
if ('\b' == c)
{
- iv_pos--;
+ if (iv_pos > 0)
+ {
+ iv_pos--;
+ }
}
else if (iv_pos < iv_size)
{
@@ -44,6 +49,19 @@ class SprintfBuffer : public Util::ConsoleBufferInterface
return c;
}
+ void nullTerminate()
+ {
+ if (iv_size > 0)
+ {
+ if (iv_pos >= iv_size)
+ {
+ iv_pos = iv_size - 1;
+ }
+
+ putc('\0');
+ }
+ }
+
explicit SprintfBuffer(char* buf, size_t size = UINT64_MAX) :
iv_pos(0), iv_size(size), iv_buffer(buf) {};
@@ -66,7 +84,7 @@ int sprintf(char *str, const char * format, ...)
size_t count = vasprintf(console, format, args);
va_end(args);
- console.putc('\0');
+ console.nullTerminate();
return count;
}
@@ -81,7 +99,7 @@ int snprintf(char *str, size_t size, const char * format, ...)
size_t count = vasprintf(console, format, args);
va_end(args);
- console.putc('\0');
+ console.nullTerminate();
return count;
}
@@ -92,7 +110,7 @@ int vsprintf(char *str, const char * format, va_list args)
SprintfBuffer console(str);
size_t count = vasprintf(console, format, args);
- console.putc('\0');
+ console.nullTerminate();
return count;
}
@@ -101,6 +119,6 @@ int vsnprintf(char *str, size_t size, const char * format, va_list args)
SprintfBuffer console(str, size);
size_t count = vasprintf(console, format, args);
- console.putc('\0');
+ console.nullTerminate();
return count;
}
OpenPOWER on IntegriCloud