Browse Source

Fixes from review by @Hoikas

Michael Hansen 12 years ago
parent
commit
58a8034eb7
  1. 40
      Sources/Plasma/NucleusLib/pnNetProtocol/Private/pnNpCommon.cpp
  2. 14
      Sources/Plasma/PubUtilLib/plVault/plVaultClientApi.cpp
  3. 2
      Sources/Plasma/PubUtilLib/plVault/plVaultNodeAccess.cpp

40
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""); *plhs = StrDup(L"");
} }
//============================================================================
template <typename T>
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; } using namespace pnNpCommon;

14
Sources/Plasma/PubUtilLib/plVault/plVaultClientApi.cpp

@ -1476,7 +1476,7 @@ static void IGetStringFieldValue (
) { ) {
wchar_t * tmp = (wchar_t*)malloc(sizeof(wchar_t) * dstChars); wchar_t * tmp = (wchar_t*)malloc(sizeof(wchar_t) * dstChars);
IStrSqlEscape(value, tmp, dstChars); IStrSqlEscape(value, tmp, dstChars);
StrPrintf(dst, dstChars, L"'%s'", tmp); swprintf(dst, dstChars, L"'%s'", tmp);
free(tmp); free(tmp);
} }
@ -1485,7 +1485,7 @@ static void IGetUuidFieldValue (
wchar_t * dst, wchar_t * dst,
size_t dstChars 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 ( static void IGetUintFieldValue (
@ -1493,7 +1493,7 @@ static void IGetUintFieldValue (
wchar_t * dst, wchar_t * dst,
size_t dstChars size_t dstChars
) { ) {
StrPrintf(dst, dstChars, L"%u", value); swprintf(dst, dstChars, L"%u", value);
} }
static void IGetIntFieldValue ( static void IGetIntFieldValue (
@ -1501,7 +1501,7 @@ static void IGetIntFieldValue (
wchar_t * dst, wchar_t * dst,
size_t dstChars 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) { 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; break;
#define STPRINT(flag, func) case k##flag: { \ #define STPRINT(flag, func) case k##flag: { \
StrPack(str, L", " L ## #flag L"=", arrsize(str)); \ wcsncat(str, L", " L ## #flag L"=", arrsize(str)); \
const size_t chars = StrLen(str); \ const size_t chars = wcslen(str); \
func(Get##flag(), str + chars, arrsize(str) - chars * sizeof(str[0])); \ func(Get##flag(), str + chars, arrsize(str) - chars * sizeof(str[0])); \
}; break }; break
#define STNAME(flag) case k##flag: { \ #define STNAME(flag) case k##flag: { \
StrPack(str, L", " L ## #flag, arrsize(str)); \ wcsncat(str, L", " L ## #flag, arrsize(str)); \
}; break }; break
switch (bit) { switch (bit) {
STPRINT(NodeId, IGetUintFieldValue); STPRINT(NodeId, IGetUintFieldValue);

2
Sources/Plasma/PubUtilLib/plVault/plVaultNodeAccess.cpp

@ -187,7 +187,7 @@ void VaultTextNoteNode::SetVisitInfo (const plAgeInfoStruct & info) {
bool VaultTextNoteNode::GetVisitInfo (plAgeInfoStruct * info) { bool VaultTextNoteNode::GetVisitInfo (plAgeInfoStruct * info) {
wchar_t * mem; wchar_t * mem;
const wchar_t * str = mem = StrDup(GetNoteText()); const wchar_t * str = mem = wcsdup(GetNoteText());
for (unsigned i = 0; i < kNumAgeInfoFields; ++i) { for (unsigned i = 0; i < kNumAgeInfoFields; ++i) {

Loading…
Cancel
Save