unaccent: Fix allocation size for target characters on initial load
authorMichael Paquier <michael@paquier.xyz>
Mon, 25 Sep 2023 00:31:48 +0000 (09:31 +0900)
committerMichael Paquier <michael@paquier.xyz>
Mon, 25 Sep 2023 00:31:48 +0000 (09:31 +0900)
This led to an overestimation of the size allocated for both the quoted
and non-quoted cases, while using an inconsistent style.  Thinkos in
59f47fb98dab.

Per report from Coverity, with extra input from Tom Lane.

contrib/unaccent/unaccent.c

index 5635f042145d22bc5b22f8584c4c9e8d9cd0b5f3..544246e37f1ff12021e1f513bdbbfc24749777f4 100644 (file)
@@ -238,7 +238,7 @@ initTrie(const char *filename)
                if (trgquoted && state > 0)
                {
                    /* Ignore first and end quotes */
-                   trgstore = palloc0(sizeof(char *) * trglen - 2);
+                   trgstore = (char *) palloc(sizeof(char) * (trglen - 2));
                    trgstorelen = 0;
                    for (int i = 1; i < trglen - 1; i++)
                    {
@@ -251,7 +251,7 @@ initTrie(const char *filename)
                }
                else
                {
-                   trgstore = palloc0(sizeof(char *) * trglen);
+                   trgstore = (char *) palloc(sizeof(char) * trglen);
                    trgstorelen = trglen;
                    memcpy(trgstore, trg, trgstorelen);
                }