summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Lane2011-11-03 23:17:48 +0000
committerTom Lane2011-11-03 23:17:48 +0000
commite3e3087d8717c26cd1c4581ba29274ac214eb816 (patch)
tree7560f858a60622db010625f33e668c816919ec81
parenta0d2f05a0d433ab68ec378744ff920562a5ef681 (diff)
Fix bogus code in contrib/ tsearch dictionary examples.
Both dict_int and dict_xsyn were blithely assuming that whatever memory palloc gives back will be pre-zeroed. This would typically work for just about long enough to run their regression tests, and no longer :-(. The pre-9.0 code in dict_xsyn was even lamer than that, as it would happily give back a pointer to the result of palloc(0), encouraging its caller to access off the end of memory. Again, this would just barely fail to fail as long as memory contained nothing but zeroes. Per a report from Rodrigo Hjort that code based on these examples didn't work reliably.
-rw-r--r--contrib/dict_int/dict_int.c2
-rw-r--r--contrib/dict_xsyn/dict_xsyn.c2
2 files changed, 3 insertions, 1 deletions
diff --git a/contrib/dict_int/dict_int.c b/contrib/dict_int/dict_int.c
index 9f61447160..68964548a6 100644
--- a/contrib/dict_int/dict_int.c
+++ b/contrib/dict_int/dict_int.c
@@ -72,7 +72,7 @@ dintdict_lexize(PG_FUNCTION_ARGS)
DictInt *d = (DictInt *) PG_GETARG_POINTER(0);
char *in = (char *) PG_GETARG_POINTER(1);
char *txt = pnstrdup(in, PG_GETARG_INT32(2));
- TSLexeme *res = palloc(sizeof(TSLexeme) * 2);
+ TSLexeme *res = palloc0(sizeof(TSLexeme) * 2);
res[1].lexeme = NULL;
if (PG_GETARG_INT32(2) > d->maxlen)
diff --git a/contrib/dict_xsyn/dict_xsyn.c b/contrib/dict_xsyn/dict_xsyn.c
index 3c05a1ea90..d47315bd79 100644
--- a/contrib/dict_xsyn/dict_xsyn.c
+++ b/contrib/dict_xsyn/dict_xsyn.c
@@ -244,6 +244,8 @@ dxsyn_lexize(PG_FUNCTION_ARGS)
if (pos != value || d->keeporig)
{
res[nsyns].lexeme = pnstrdup(syn, end - syn);
+ res[nsyns].nvariant = 0;
+ res[nsyns].flags = 0;
nsyns++;
}