]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/lib/bsnprintf.c
Pull compiler warning cleanup code + other from master
[bacula/bacula] / bacula / src / lib / bsnprintf.c
index 5fa592610b248e75f4ec1f990d227098db6ad92b..afef57c1d9a1eafc1665cd6904cd832968ba2590 100644 (file)
@@ -1,12 +1,12 @@
 /*
    Bacula® - The Network Backup Solution
 
-   Copyright (C) 2005-2010 Free Software Foundation Europe e.V.
+   Copyright (C) 2005-2012 Free Software Foundation Europe e.V.
 
    The main author of Bacula is Kern Sibbald, with contributions from
    many others, a complete list can be found in the file AUTHORS.
    This program is Free Software; you can redistribute it and/or
-   modify it under the terms of version two of the GNU General Public
+   modify it under the terms of version three of the GNU Affero General Public
    License as published by the Free Software Foundation and included
    in the file LICENSE.
 
@@ -15,7 +15,7 @@
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
    General Public License for more details.
 
-   You should have received a copy of the GNU General Public License
+   You should have received a copy of the GNU Affero General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
    02110-1301, USA.
@@ -115,6 +115,7 @@ static int32_t fmtfp(char *buffer, int32_t currlen, int32_t maxlen,
 #define DP_C_LDOUBLE  3
 #define DP_C_INT64    4
 #define DP_C_WCHAR    5      /* wide characters */
+#define DP_C_SIZE_T   6
 
 #define char_to_int(p) ((p)- '0')
 #undef MAX
@@ -250,6 +251,10 @@ int bvsnprintf(char *buffer, int32_t maxlen, const char *format, va_list args)
                ch = *format++;
             }
             break;
+         case 'z':
+            cflags = DP_C_SIZE_T;
+            ch = *format++;
+            break;
          case 'L':
             cflags = DP_C_LDOUBLE;
             ch = *format++;
@@ -273,6 +278,8 @@ int bvsnprintf(char *buffer, int32_t maxlen, const char *format, va_list args)
                value = va_arg(args, int32_t);
             } else if (cflags == DP_C_INT64) {
                value = va_arg(args, int64_t);
+            } else if (cflags == DP_C_SIZE_T) {
+               value = va_arg(args, ssize_t);
             } else {
                value = va_arg(args, int);
             }
@@ -299,6 +306,8 @@ int bvsnprintf(char *buffer, int32_t maxlen, const char *format, va_list args)
                value = va_arg(args, uint32_t);
             } else if (cflags == DP_C_INT64) {
                value = va_arg(args, uint64_t);
+            } else if (cflags == DP_C_SIZE_T) {
+               value = va_arg(args, size_t);
             } else {
                value = va_arg(args, unsigned int);
             }
@@ -339,10 +348,16 @@ int bvsnprintf(char *buffer, int32_t maxlen, const char *format, va_list args)
          case 's':
             if (cflags != DP_C_WCHAR) {
               strvalue = va_arg(args, char *);
+              if (!strvalue) {
+                 strvalue = (char *)"<NULL>";
+              }
               currlen = fmtstr(buffer, currlen, maxlen, strvalue, flags, min, max);
             } else {
               /* %ls means to edit wide characters */
               wstrvalue = va_arg(args, wchar_t *);
+              if (!wstrvalue) {
+                 wstrvalue = (wchar_t *)L"<NULL>";
+              }
               currlen = fmtwstr(buffer, currlen, maxlen, wstrvalue, flags, min, max);
             }
             break;
@@ -357,33 +372,28 @@ int bvsnprintf(char *buffer, int32_t maxlen, const char *format, va_list args)
             }
             currlen = fmtint(buffer, currlen, maxlen, value, 16, min, max, flags);
             break;
+
+#ifdef SECURITY_PROBLEM
          case 'n':
             if (cflags == DP_C_INT16) {
                int16_t *num;
                num = va_arg(args, int16_t *);
-#ifdef SECURITY_PROBLEM
                *num = currlen;
-#endif
             } else if (cflags == DP_C_INT32) {
                int32_t *num;
                num = va_arg(args, int32_t *);
-#ifdef SECURITY_PROBLEM
                *num = (int32_t)currlen;
-#endif
             } else if (cflags == DP_C_INT64) {
                int64_t *num;
                num = va_arg(args, int64_t *);
-#ifdef SECURITY_PROBLEM
                *num = (int64_t)currlen;
-#endif
             } else {
                int32_t *num;
                num = va_arg(args, int32_t *);
-#ifdef SECURITY_PROBLEM
                *num = (int32_t)currlen;
-#endif
             }
             break;
+#endif
          case '%':
             outch(ch);
             break;
@@ -428,9 +438,6 @@ static int32_t fmtstr(char *buffer, int32_t currlen, int32_t maxlen,
    } else if (max < 0) {
       max = maxlen;
    }
-   if (!value) {
-      value = "<NULL>";
-   }
    strln = strlen(value);
    if (strln > max) {
       strln = max;                /* truncate to max */
@@ -472,9 +479,6 @@ static int32_t fmtwstr(char *buffer, int32_t currlen, int32_t maxlen,
    } else if (max < 0) {
       max = maxlen;
    }
-   if (!value) {
-      value = L"<NULL>";
-   }
    strln = wcslen(value);
    if (strln > max) {
       strln = max;                /* truncate to max */
@@ -743,6 +747,7 @@ static int32_t fmtfp(char *buffer, int32_t currlen, int32_t maxlen,
 
    if (!result) {
       r_length = 0;
+      dummy[0] = 0;
       result = dummy;
    } else {
       r_length = strlen(result);