From: Wilfried Göesgens Date: Sat, 17 Jan 2009 10:22:09 +0000 (+0000) Subject: * make error logging NULL safe. X-Git-Tag: v7.86~1602 X-Git-Url: https://code.citadel.org/?p=citadel.git;a=commitdiff_plain;h=37f24665aefea1dccb6a5646cd88debba576fdd6 * make error logging NULL safe. --- diff --git a/webcit/subst.c b/webcit/subst.c index c32448c7b..249a88699 100644 --- a/webcit/subst.c +++ b/webcit/subst.c @@ -88,7 +88,8 @@ const char *CtxNames[] = { "Context LONGVECTOR", "Context ROOMS", "Context FLOORS", - "Context ITERATE" + "Context ITERATE", + "Context UNKNOWN" }; @@ -101,6 +102,14 @@ void DestroySortStruct(void *vSort) free (Sort); } +const char *ContextName(int ContextType) +{ + if (ContextType < CTX_UNKNOWN) + return CtxNames[ContextType]; + else + return CtxNames[CTX_UNKNOWN]; +} + void LogTemplateError (StrBuf *Target, const char *Type, int ErrorPos, WCTemplputParams *TP, const char *Format, ...) { StrBuf *Error; @@ -118,23 +127,35 @@ void LogTemplateError (StrBuf *Target, const char *Type, int ErrorPos, WCTemplpu switch (ErrorPos) { default: case ERR_NAME: /* the main token name... */ - Err = TP->Tokens->pName; + Err = (TP->Tokens!= NULL)? TP->Tokens->pName:""; break; case ERR_PARM1: - Err = TP->Tokens->Params[0]->Start; + Err = (TP->Tokens!= NULL)? TP->Tokens->Params[0]->Start:""; break; case ERR_PARM2: - Err = TP->Tokens->Params[1]->Start; + Err = (TP->Tokens!= NULL)? TP->Tokens->Params[1]->Start:""; break; } - lprintf(1, "%s [%s] (in '%s' line %ld); %s; [%s]\n", - Type, - Err, - ChrPtr(TP->Tokens->FileName), - TP->Tokens->Line, - ChrPtr(Error), - ChrPtr(TP->Tokens->FlatToken)); - if (Target != NULL) { + if (TP->Tokens != NULL) + { + lprintf(1, "%s [%s] (in '%s' line %ld); %s; [%s]\n", + Type, + Err, + ChrPtr(TP->Tokens->FileName), + TP->Tokens->Line, + ChrPtr(Error), + ChrPtr(TP->Tokens->FlatToken)); + } + else + { + lprintf(1, "%s: %s;\n", + Type, + ChrPtr(Error)); + } + if (Target == NULL) + return; + if (TP->Tokens != NULL) + { StrBufAppendPrintf( Target, "
\n%s [%s] (in '%s' line %ld); %s\n[%s]\n
\n", @@ -145,6 +166,14 @@ void LogTemplateError (StrBuf *Target, const char *Type, int ErrorPos, WCTemplpu ChrPtr(Error), ChrPtr(TP->Tokens->FlatToken)); } + else + { + StrBufAppendPrintf( + Target, + "
\n%s: %s\n
\n", + Type, + ChrPtr(Error)); + } } @@ -194,8 +223,8 @@ int CheckContext(StrBuf *Target, ContextFilter *Need, WCTemplputParams *TP, cons LogTemplateError( Target, ErrType, ERR_PARM1, TP, " WARNING: requires Context: [%s], have [%s]!", - CtxNames[Need->ContextType], - CtxNames[TP->Filter.ContextType]); + ContextName(Need->ContextType), + ContextName(TP->Filter.ContextType)); return 0; } @@ -204,8 +233,8 @@ int CheckContext(StrBuf *Target, ContextFilter *Need, WCTemplputParams *TP, cons LogTemplateError( Target, ErrType, ERR_PARM1, TP, " WARNING: requires Control Context: [%s], have [%s]!", - CtxNames[Need->ControlContextType], - CtxNames[TP->Filter.ControlContextType]); + ContextName(Need->ControlContextType), + ContextName(TP->Filter.ControlContextType)); return 0; } /* diff --git a/webcit/subst.h b/webcit/subst.h index 466e6aee2..37ce34fe5 100644 --- a/webcit/subst.h +++ b/webcit/subst.h @@ -51,6 +51,8 @@ enum { #define CTX_FLOORS 15 #define CTX_ITERATE 16 +#define CTX_UNKNOWN 17 + /** * ContextFilter resembles our RTTI information. With this structure