From 31ee1880adc079678288a773d34a118429f700da Mon Sep 17 00:00:00 2001 From: Micke Prag Date: Mon, 18 Jun 2012 16:07:18 +0200 Subject: [PATCH] Use sizeof(varname) instead of sizeof(type) according to Google style guidelines "runtime/sizeof" --- telldus-core/common/Strings.cpp | 7 ++++--- telldus-core/common/common.h | 3 ++- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/telldus-core/common/Strings.cpp b/telldus-core/common/Strings.cpp index 6b2f1bf2..29aca4a6 100644 --- a/telldus-core/common/Strings.cpp +++ b/telldus-core/common/Strings.cpp @@ -178,7 +178,7 @@ std::string TelldusCore::wideToString(const std::wstring &input) { } char *buffer; buffer = new char[size]; - memset(buffer, 0, sizeof(char)*size); + memset(buffer, 0, sizeof(*buffer)*size); int bytes = WideCharToMultiByte(CP_UTF8, 0, input.c_str(), -1, buffer, size, NULL, NULL); std::string retval(buffer); @@ -187,7 +187,8 @@ std::string TelldusCore::wideToString(const std::wstring &input) { #else size_t wideSize = sizeof(wchar_t)*input.length(); - size_t outbytesLeft = wideSize+sizeof(char); // We cannot know how many wide character there is yet + // We cannot know how many wide character there is yet + size_t outbytesLeft = wideSize+sizeof(char); // NOLINT(runtime/sizeof) // Copy the instring char *inString = (char*)new wchar_t[input.length()+1]; @@ -195,7 +196,7 @@ std::string TelldusCore::wideToString(const std::wstring &input) { // Create buffer for output char *outString = new char[outbytesLeft]; - memset(outString, 0, sizeof(char)*(outbytesLeft)); + memset(outString, 0, sizeof(*outString)*(outbytesLeft)); #ifdef _FREEBSD const char *inPointer = inString; diff --git a/telldus-core/common/common.h b/telldus-core/common/common.h index 13e39bda..bbb0a783 100644 --- a/telldus-core/common/common.h +++ b/telldus-core/common/common.h @@ -69,7 +69,8 @@ inline char *wrapStdString( const std::string &string) { #ifdef _WINDOWS return (char *)SysAllocStringByteLen(string.c_str(), (unsigned int)string.size()); #else - char *returnVal = (char *)malloc(sizeof(char) * (string.size()+1)); + char *returnVal; + returnVal = (char *)malloc(sizeof(*returnVal) * (string.size()+1)); strcpy(returnVal, string.c_str()); return returnVal; #endif