8000 Fix bogus code in contrib/ tsearch dictionary examples. · jaylevitt/postgres@92375ed · GitHub
[go: up one dir, main page]

Skip to content

Commit 92375ed

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 1819a37 commit 92375ed

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

contrib/dict_int/dict_int.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ dintdict_lexize(PG_FUNCTION_ARGS)
7373
DictInt *d = (DictInt *) PG_GETARG_POINTER(0);
7474
char *in = (char *) PG_GETARG_POINTER(1);
7575
char *txt = pnstrdup(in, PG_GETARG_INT32(2));
76-
TSLexeme *res = palloc(sizeof(TSLexeme) * 2);
76+
TSLexeme *res = palloc0(sizeof(TSLexeme) * 2);
7777

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

contrib/dict_xsyn/dict_xsyn.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,8 @@ dxsyn_lexize(PG_FUNCTION_ARGS)
245245
if (pos != value || d->keeporig)
246246
{
247247
res[nsyns].lexeme = pnstrdup(syn, end - syn);
248+
res[nsyns].nvariant = 0;
249+
res[nsyns].flags = 0;
248250
nsyns++;
249251
}
250252

0 commit comments

Comments
 (0)
0