Remove a static fstring
authorVolker Lendecke <vl@samba.org>
Sat, 15 Dec 2007 23:03:56 +0000 (00:03 +0100)
committerVolker Lendecke <vl@samba.org>
Sun, 16 Dec 2007 13:02:26 +0000 (14:02 +0100)
source/lib/version.c

index ca334a27d9d2fefca9c11af212577421672636bb..204c2044a8d2576f988d9d49011a93b34f7c972b 100644 (file)
 */
 
 #include "includes.h"
+#include <assert.h>
 
 const char *samba_version_string(void)
 {
 #ifndef SAMBA_VERSION_VENDOR_SUFFIX
        return SAMBA_VERSION_OFFICIAL_STRING;
 #else
-       static fstring samba_version;
-       static bool init_samba_version;
+       static char *samba_version;
+       int res;
 #ifdef SAMBA_VERSION_VENDOR_PATCH
-       fstring tmp_version;
-       size_t remaining;
+       char *tmp_version;
 #endif
 
-       if (init_samba_version)
+       if (samba_version != NULL)
                return samba_version;
 
-       snprintf(samba_version,sizeof(samba_version),"%s-%s",
-               SAMBA_VERSION_OFFICIAL_STRING,
-               SAMBA_VERSION_VENDOR_SUFFIX);
+       res = asprintf(&samba_version, "%s-%s",
+                      SAMBA_VERSION_OFFICIAL_STRING,
+                      SAMBA_VERSION_VENDOR_SUFFIX);
+       /*
+        * Can't use smb_panic here due to dependencies
+        */
+       assert(res != -1);
 
 #ifdef SAMBA_VERSION_VENDOR_PATCH
-       remaining = sizeof(samba_version)-strlen(samba_version);
-       snprintf( tmp_version, sizeof(tmp_version),  "-%d", SAMBA_VERSION_VENDOR_PATCH );
-       strlcat( samba_version, tmp_version, remaining-1 );
+       res = asprintf(&tmp_version, "%s-%d", samba_version,
+                      SAMBA_VERSION_VENDOR_PATCH);
+       /*
+        * Can't use smb_panic here due to dependencies
+        */
+       assert(res != -1);
+
+       samba_version = tmp_version;
 #endif
 
-       init_samba_version = True;
        return samba_version;
 #endif
 }