Date: Thu, 25 Aug 2011 00:25:16 +0000 (UTC) From: Gabor Kovesdan <gabor@FreeBSD.org> To: src-committers@freebsd.org, svn-src-user@freebsd.org Subject: svn commit: r225158 - user/gabor/tre-integration/contrib/tre/lib Message-ID: <201108250025.p7P0PGVZ076799@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: gabor Date: Thu Aug 25 00:25:15 2011 New Revision: 225158 URL: http://svn.freebsd.org/changeset/base/225158 Log: - Add proper error checking for hashtable-related errors Modified: user/gabor/tre-integration/contrib/tre/lib/tre-fastmatch.c Modified: user/gabor/tre-integration/contrib/tre/lib/tre-fastmatch.c ============================================================================== --- user/gabor/tre-integration/contrib/tre/lib/tre-fastmatch.c Thu Aug 25 00:14:30 2011 (r225157) +++ user/gabor/tre-integration/contrib/tre/lib/tre-fastmatch.c Thu Aug 25 00:25:15 2011 (r225158) @@ -46,6 +46,18 @@ static int fastcmp(const void *, const void *, size_t, tre_str_type_t, bool, bool); +#define FAIL_COMP(errcode) \ + { \ + if (fg->pattern) \ + xfree(fg->pattern); \ + if (fg->wpattern) \ + xfree(fg->wpattern); \ + if (fg->qsBc_table) \ + hashtable_free(fg->qsBc_table); \ + fg = NULL; \ + return errcode; \ + } + /* * Skips n characters in the input string and assigns the start * address to startptr. Note: as per IEEE Std 1003.1-2008 @@ -222,17 +234,25 @@ static int fastcmp(const void *, const v /* Preprocess pattern. */ \ fg->qsBc_table = hashtable_init(fg->wlen * 4, sizeof(tre_char_t), \ sizeof(int)); \ + if (!fg->qsBc_table) \ + FAIL_COMP(REG_ESPACE); \ for (unsigned int i = fg->hasdot + 1; i < fg->wlen; i++) \ { \ int k = fg->wlen - i; \ - hashtable_put(fg->qsBc_table, &fg->wpattern[i], &k); \ + int r; \ + \ + r = hashtable_put(fg->qsBc_table, &fg->wpattern[i], &k); \ + if ((r == HASH_FAIL) || (r == HASH_FULL)) \ + FAIL_COMP(REG_ESPACE); \ DPRINT(("BC shift for wide char %lc is %d\n", fg->wpattern[i], \ fg->wlen - i)); \ if (fg->icase) \ { \ tre_char_t wc = iswlower(fg->wpattern[i]) ? \ towupper(fg->wpattern[i]) : towlower(fg->wpattern[i]); \ - hashtable_put(fg->qsBc_table, &wc, &k); \ + r = hashtable_put(fg->qsBc_table, &wc, &k); \ + if ((r == HASH_FAIL) || (r == HASH_FULL)) \ + FAIL_COMP(REG_ESPACE); \ } \ }
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201108250025.p7P0PGVZ076799>