From: Radosław Korzeniewski Date: Tue, 17 Nov 2020 14:11:02 +0000 (+0100) Subject: docker: Fix variable not initialized in the constructor. X-Git-Tag: Release-11.3.2~754 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2c61b887a6be573f95b8cf69b36e85ef36e47d69;p=thirdparty%2Fbacula.git docker: Fix variable not initialized in the constructor. --- diff --git a/bacula/src/plugins/fd/docker/dkid.c b/bacula/src/plugins/fd/docker/dkid.c index 7813d9548..3430aeb52 100644 --- a/bacula/src/plugins/fd/docker/dkid.c +++ b/bacula/src/plugins/fd/docker/dkid.c @@ -29,27 +29,18 @@ /* * DKID class constructor, does default initialization. */ -DKID::DKID() -{ - bmemzero(Digest, DKIDDIGESTSIZE + 1); - ShortD = DKIDInvalid; - shortonly = false; -}; - -/* - * DKID class constructor, does parm initialization. - */ -DKID::DKID(const char* data) -{ - init(data); -}; - -/* - * DKID class constructor, does parm initialization. - */ -DKID::DKID(POOL_MEM& data) +DKID::DKID() : + ShortD(DKIDInvalid), +#if __cplusplus > 201103L + Digest{0}, + DigestShort{0}, +#endif + shortonly(false) { - init(data.c_str()); +#if ! __cplusplus > 201103L + bmemzero(Digest, DKIDDIGESTSIZE_Len); + bmemzero(DigestShort, DKIDDIGESTShortSIZE_Len); +#endif }; /* @@ -60,10 +51,6 @@ DKID::DKID(POOL_MEM& data) */ void DKID::init(const char* data) { - int len; - int a; - unsigned char c; - bool valid = true; char *dig = (char*)data; if (dig != NULL){ @@ -71,11 +58,12 @@ void DKID::init(const char* data) if (strstr(dig, "sha256:") == dig){ dig += 7; } - len = strlen(dig); + int len = strlen(dig); /* check for invalid input data */ - for (a = 0; a < (len > DKIDDIGESTShortSIZE ? DKIDDIGESTShortSIZE : len); a++){ + bool valid = true; + for (int a = 0; a < (len > DKIDDIGESTShortSIZE ? DKIDDIGESTShortSIZE : len); a++){ // we are checking for ASCII codes, a subset of UTF-8 for short digest only - c = (unsigned char)dig[a]; + unsigned char c = (unsigned char)dig[a]; if (c > 'f' || (c > '9' && c < 'A') || (c > 'F' && c < 'a')){ valid = false; break; @@ -350,4 +338,4 @@ int main() return report(); }; -#endif /* TEST_PROGRAM */ \ No newline at end of file +#endif /* TEST_PROGRAM */ diff --git a/bacula/src/plugins/fd/docker/dkid.h b/bacula/src/plugins/fd/docker/dkid.h index cca496f5b..47e1ad5de 100644 --- a/bacula/src/plugins/fd/docker/dkid.h +++ b/bacula/src/plugins/fd/docker/dkid.h @@ -29,39 +29,46 @@ #include "bacula.h" -#define DKIDDIGESTSIZE 64 // the size of string array for hex chars, without trailing nul -#define DKIDDIGESTShortSIZE 12 // the number of hex characters in short digest, without trailing nul -#define DKIDInvalid -256 // the non-trivial negative value :) +#define DKIDDIGESTSIZE 64 // the size of string array for hex chars, without trailing nul +#define DKIDDIGESTSIZE_Len (DKIDDIGESTSIZE + 1) // the size of string array for hex chars, with trailing nul +#define DKIDDIGESTShortSIZE 12 // the number of hex characters in short digest, without trailing nul +#define DKIDDIGESTShortSIZE_Len (DKIDDIGESTShortSIZE + 1) // the number of hex characters in short digest, without trailing nul +#define DKIDInvalid -256 // the non-trivial negative value :) /* * This is a simple storage class to handle Docker Container IDs */ -class DKID: public SMARTALLOC { - public: - DKID(); - DKID(const char *data); - DKID(POOL_MEM &data); - ~DKID() {}; +class DKID: public SMARTALLOC +{ +public: + DKID(); + DKID(const char *data) { init(data); } + DKID(POOL_MEM &data) { init(data.c_str()); } +#if __cplusplus > 201103L + ~DKID() = default; +#else + ~DKID() {}; +#endif - inline int64_t id() { return ShortD; }; - inline char *digest() { return Digest; }; - inline char *digest_short() { return DigestShort; }; - inline operator int64_t () { return ShortD; }; - inline operator char* () { return Digest; }; - DKID& operator= (char *data); - DKID& operator= (DKID &other); - DKID& operator= (POOL_MEM &data); - bool operator== (DKID &other); - bool operator!= (DKID &other); + inline int64_t id() { return ShortD; }; + inline char *digest() { return Digest; }; + inline char *digest_short() { return DigestShort; }; + inline operator int64_t () { return ShortD; }; + inline operator char* () { return Digest; }; + DKID& operator= (char *data); + DKID& operator= (DKID &other); + DKID& operator= (POOL_MEM &data); + bool operator== (DKID &other); + bool operator!= (DKID &other); #ifdef TEST_PROGRAM - void dump(); + void dump(); #endif - private: - char Digest[DKIDDIGESTSIZE + 1]; - char DigestShort[DKIDDIGESTShortSIZE + 1]; +private: int64_t ShortD; // default short digest on Docker is 48bits/6bytes/12hex chars // https://github.com/docker/cli/blob/master/vendor/github.com/docker/docker/pkg/stringid/stringid.go + char Digest[DKIDDIGESTSIZE_Len]; + char DigestShort[DKIDDIGESTShortSIZE_Len]; bool shortonly; void init(const char* d);