From 1cad8468cbaf61309a64194fca547a67a700a6da Mon Sep 17 00:00:00 2001 From: fusion32 Date: Sat, 12 Jul 2025 20:44:10 -0300 Subject: house related queries --- src/querymanager.cc | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'src/querymanager.cc') diff --git a/src/querymanager.cc b/src/querymanager.cc index 57b3ef9..7d6c830 100644 --- a/src/querymanager.cc +++ b/src/querymanager.cc @@ -112,17 +112,21 @@ bool StringEqCI(const char *A, const char *B){ bool StringCopyN(char *Dest, int DestCapacity, const char *Src, int SrcLength){ ASSERT(DestCapacity > 0); bool Result = (SrcLength < DestCapacity); - if(Result){ + if(Result && SrcLength > 0){ memcpy(Dest, Src, SrcLength); Dest[SrcLength] = 0; }else{ Dest[0] = 0; } - return true; + return Result; } bool StringCopy(char *Dest, int DestCapacity, const char *Src){ - return StringCopyN(Dest, DestCapacity, Src, (int)strlen(Src)); + // IMPORTANT(fusion): `sqlite3_column_text` may return NULL if the column is + // also NULL so we have an incentive to properly handle the case where `Src` + // is NULL. + int SrcLength = (Src != NULL ? (int)strlen(Src) : 0); + return StringCopyN(Dest, DestCapacity, Src, SrcLength); } bool ReadBooleanConfig(bool *Dest, const char *Val){ -- cgit v1.2.3