Skip to content

Commit e3e3087

Browse files
committed
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.
1 parent a0d2f05 commit e3e3087

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

contrib/dict_int/dict_int.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ dintdict_lexize(PG_FUNCTION_ARGS)
7272
DictInt *d = (DictInt *) PG_GETARG_POINTER(0);
7373
char *in = (char *) PG_GETARG_POINTER(1);
7474
char *txt = pnstrdup(in, PG_GETARG_INT32(2));
75-
TSLexeme *res = palloc(sizeof(TSLexeme) * 2);
75+
TSLexeme *res = palloc0(sizeof(TSLexeme) * 2);
7676

7777
res[1].lexeme = NULL;
7878
if (PG_GETARG_INT32(2) > d->maxlen)

contrib/dict_xsyn/dict_xsyn.c

+2
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,8 @@ dxsyn_lexize(PG_FUNCTION_ARGS)
244244
if (pos != value || d->keeporig)
245245
{
246246
res[nsyns].lexeme = pnstrdup(syn, end - syn);
247+
res[nsyns].nvariant = 0;
248+
res[nsyns].flags = 0;
247249
nsyns++;
248250
}
249251

0 commit comments

Comments
 (0)