From 962952a442b74a5d5fe365f77ab5481bc3cd3eba Mon Sep 17 00:00:00 2001 From: Chip Black Date: Sun, 16 Jan 2011 06:08:22 -0600 Subject: [PATCH] tags must be preceeded by whitespace or start at the beginning of the record --- config.h | 3 +++ database/tags.c | 14 ++++++++------ 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/config.h b/config.h index 9a16246..b363206 100644 --- a/config.h +++ b/config.h @@ -10,4 +10,7 @@ #define RECORDS_PER_SEGMENT 65536 #define MAX_RECORD_SIZE 65535 /* No greater than 65535 */ +#define MAX_TAG_LENGTH 64 +#define MAX_TAGS_PER_RECORD 1024 + #endif //_CONFIG_H diff --git a/database/tags.c b/database/tags.c index 8386705..a28df02 100644 --- a/database/tags.c +++ b/database/tags.c @@ -14,20 +14,19 @@ #include "util.h" #include "config.h" -#define MAX_TAG_LENGTH 64 -#define MAX_TAGS 1024 - #define TAG_CHAR(c) ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9') || c == '-' || c == '_') +#define WHITESPACE(c) (c == ' ' || c == '\t' || c == '\n' || c == '\r') int tag_scan(const char *author, const char *data, int len, uint64_t record) { - char *taglist[MAX_TAGS]; + char *taglist[MAX_TAGS_PER_RECORD]; + char last_char = ' '; int n_tags = 0; int i, j; for (i = 0; i < len; i++) { tag_scan_start: - if (data[i] == '#' || data[i] == '@') { - if (n_tags == MAX_TAGS) { + if (WHITESPACE(last_char) && (data[i] == '#' || data[i] == '@')) { + if (n_tags == MAX_TAGS_PER_RECORD) { fprintf(stderr, "Too many tags in message\n"); break; } @@ -43,14 +42,17 @@ tag_scan_start: if (!strncmp(tag, taglist[j], MAX_TAG_LENGTH)) { // We already have this tag. Start over. free(tag); + last_char = data[i-1]; goto tag_scan_start; } } taglist[n_tags] = tag; n_tags++; + last_char = data[i-1]; // We goto here so i doesn't get incremented goto tag_scan_start; } + last_char = data[i]; } for (i = 0; i < n_tags; i++) { -- 2.25.1