From 90e845843d00348eecadd2037510ca369e0bc6a5 Mon Sep 17 00:00:00 2001 From: david Date: Mon, 3 Oct 2011 04:00:26 +0000 Subject: [PATCH] Allow NULL OS_Classification components when comparing. This used to be allowed only for the generation, as a special case. --- FingerPrintResults.cc | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/FingerPrintResults.cc b/FingerPrintResults.cc index 6819be303..955a80ffa 100644 --- a/FingerPrintResults.cc +++ b/FingerPrintResults.cc @@ -267,16 +267,25 @@ void FingerPrintResults::populateClassification() { return; } +/* Return true iff s and t are both NULL or both the same string. */ +static bool strnulleq(const char *s, const char *t) { + if (s == NULL && t == NULL) + return true; + else if (s == NULL || t == NULL) + return false; + else + return strcmp(s, t) == 0; +} + // Go through any previously enterted classes to see if this is a dupe; bool FingerPrintResults::classAlreadyExistsInResults(struct OS_Classification *OSC) { int i; for (i=0; i < OSR.OSC_num_matches; i++) { - if (!strcmp(OSC->OS_Vendor, OSR.OSC[i]->OS_Vendor) && - !strcmp(OSC->OS_Family, OSR.OSC[i]->OS_Family) && - !strcmp(OSC->Device_Type, OSR.OSC[i]->Device_Type) && - !strcmp(OSC->OS_Generation? OSC->OS_Generation : "", - OSR.OSC[i]->OS_Generation? OSR.OSC[i]->OS_Generation : "")) { + if (strnulleq(OSC->OS_Vendor, OSR.OSC[i]->OS_Vendor) && + strnulleq(OSC->OS_Family, OSR.OSC[i]->OS_Family) && + strnulleq(OSC->Device_Type, OSR.OSC[i]->Device_Type) && + strnulleq(OSC->OS_Generation, OSR.OSC[i]->OS_Generation)) { // Found a duplicate! return true; }