Hi,
Coverity detected a possible division by zero in
src/format/Format.cc line 500, on a Token->divisor.
The defect is a false positive as that value is correctly initialized,
but it could be a chance to document as a class invariant that that
value must not be zero, and initialize it to 1 in the default
constructor.
Attached patch does just that.
--
/kinkie
=== modified file 'src/format/Token.h'
--- src/format/Token.h 2013-02-11 23:11:12 +0000
+++ src/format/Token.h 2014-01-09 08:49:21 +0000
@@ -8,73 +8,73 @@
* Squid configuration allows users to define custom formats in
* several components.
* - logging
* - external ACL input
* - deny page URL
*
* These enumerations and classes define the API for parsing of
* format directives to define these patterns. Along with output
* functionality to produce formatted buffers.
*/
namespace Format
{
class TokenTableEntry;
#define LOG_BUF_SZ (MAX_URL<<2)
// XXX: inherit from linked list
class Token
{
public:
Token() : type(LFT_NONE),
label(NULL),
widthMin(-1),
widthMax(-1),
quote(LOG_QUOTE_NONE),
left(false),
space(false),
zero(false),
- divisor(0),
+ divisor(1),
next(NULL)
{ data.string = NULL; }
~Token();
/// Initialize the format token registrations
static void Init();
/** parses a single token. Returns the token length in characters,
* and fills in this item with the token information.
* def is for sure null-terminated.
*/
int parse(const char *def, enum Quoting *quote);
ByteCode_t type;
const char *label;
union {
char *string;
struct {
char *header;
char *element;
char separator;
} header;
char *timespec;
} data;
int widthMin; ///< minimum field width
int widthMax; ///< maximum field width
enum Quoting quote;
bool left;
bool space;
bool zero;
- int divisor;
+ int divisor; // class invariant: MUST NOT be zero.
Token *next; /* todo: move from linked list to array */
private:
const char *scanForToken(TokenTableEntry const table[], const char *cur);
};
} // namespace Format
#endif /* _SQUID_FORMAT_TOKEN_H */