From 58a8034eb7f4a20e25d4543c4c663e14c1c0e511 Mon Sep 17 00:00:00 2001 From: Michael Hansen Date: Sat, 5 Jan 2013 20:04:55 -0800 Subject: [PATCH] Fixes from review by @Hoikas --- .../pnNetProtocol/Private/pnNpCommon.cpp | 40 ------------------- .../PubUtilLib/plVault/plVaultClientApi.cpp | 14 +++---- .../PubUtilLib/plVault/plVaultNodeAccess.cpp | 2 +- 3 files changed, 8 insertions(+), 48 deletions(-) diff --git a/Sources/Plasma/NucleusLib/pnNetProtocol/Private/pnNpCommon.cpp b/Sources/Plasma/NucleusLib/pnNetProtocol/Private/pnNpCommon.cpp index 4aadebad..7a121af8 100644 --- a/Sources/Plasma/NucleusLib/pnNetProtocol/Private/pnNpCommon.cpp +++ b/Sources/Plasma/NucleusLib/pnNetProtocol/Private/pnNpCommon.cpp @@ -185,46 +185,6 @@ static inline void ICopyString (wchar_t ** plhs, const wchar_t rhs[]) { *plhs = StrDup(L""); } -//============================================================================ -template -static bool IStrSqlEscape (const T src[], T * dst, unsigned dstChars) { - - // count the number of ' chars - unsigned ticks = 0; - { - const T * cur = src; - while (*cur) { - if (*cur == L'\'') - ++ticks; - cur++; - } - } - - unsigned reqChars = StrLen(src) + ticks + 1; - - if (dstChars < reqChars) - // failure! - return false; - - T * cur = dst; - - // copy src to dst, escaping ' chars - while (*src) { - if (*src == L'\'') { - *cur++ = L'\''; - *cur++ = *src++; - continue; - } - *cur++ = *src++; - } - - // null-terminate dst string - *cur = 0; - - // success! - return true; -} - } using namespace pnNpCommon; diff --git a/Sources/Plasma/PubUtilLib/plVault/plVaultClientApi.cpp b/Sources/Plasma/PubUtilLib/plVault/plVaultClientApi.cpp index 0c8088cd..7c601c24 100644 --- a/Sources/Plasma/PubUtilLib/plVault/plVaultClientApi.cpp +++ b/Sources/Plasma/PubUtilLib/plVault/plVaultClientApi.cpp @@ -1476,7 +1476,7 @@ static void IGetStringFieldValue ( ) { wchar_t * tmp = (wchar_t*)malloc(sizeof(wchar_t) * dstChars); IStrSqlEscape(value, tmp, dstChars); - StrPrintf(dst, dstChars, L"'%s'", tmp); + swprintf(dst, dstChars, L"'%s'", tmp); free(tmp); } @@ -1485,7 +1485,7 @@ static void IGetUuidFieldValue ( wchar_t * dst, size_t dstChars ) { - StrPrintf(dst, dstChars, L"hextoraw('%s')", value.AsString().c_str()); + swprintf(dst, dstChars, L"hextoraw('%S')", value.AsString().c_str()); } static void IGetUintFieldValue ( @@ -1493,7 +1493,7 @@ static void IGetUintFieldValue ( wchar_t * dst, size_t dstChars ) { - StrPrintf(dst, dstChars, L"%u", value); + swprintf(dst, dstChars, L"%u", value); } static void IGetIntFieldValue ( @@ -1501,7 +1501,7 @@ static void IGetIntFieldValue ( wchar_t * dst, size_t dstChars ) { - StrPrintf(dst, dstChars, L"%d", value); + swprintf(dst, dstChars, L"%d", value); } void RelVaultNode::Print (const wchar_t tag[], FStateDump dumpProc, unsigned level) { @@ -1526,12 +1526,12 @@ void RelVaultNode::Print (const wchar_t tag[], FStateDump dumpProc, unsigned lev break; #define STPRINT(flag, func) case k##flag: { \ - StrPack(str, L", " L ## #flag L"=", arrsize(str)); \ - const size_t chars = StrLen(str); \ + wcsncat(str, L", " L ## #flag L"=", arrsize(str)); \ + const size_t chars = wcslen(str); \ func(Get##flag(), str + chars, arrsize(str) - chars * sizeof(str[0])); \ }; break #define STNAME(flag) case k##flag: { \ - StrPack(str, L", " L ## #flag, arrsize(str)); \ + wcsncat(str, L", " L ## #flag, arrsize(str)); \ }; break switch (bit) { STPRINT(NodeId, IGetUintFieldValue); diff --git a/Sources/Plasma/PubUtilLib/plVault/plVaultNodeAccess.cpp b/Sources/Plasma/PubUtilLib/plVault/plVaultNodeAccess.cpp index 09058bf6..2fccccea 100644 --- a/Sources/Plasma/PubUtilLib/plVault/plVaultNodeAccess.cpp +++ b/Sources/Plasma/PubUtilLib/plVault/plVaultNodeAccess.cpp @@ -187,7 +187,7 @@ void VaultTextNoteNode::SetVisitInfo (const plAgeInfoStruct & info) { bool VaultTextNoteNode::GetVisitInfo (plAgeInfoStruct * info) { wchar_t * mem; - const wchar_t * str = mem = StrDup(GetNoteText()); + const wchar_t * str = mem = wcsdup(GetNoteText()); for (unsigned i = 0; i < kNumAgeInfoFields; ++i) {