Skip to content

Commit a11142e

Browse files
committed
PGPRO-10866: Use const decoration to avoid warnings:
"passing 'const char *' to parameter of type 'char *' discards qualifiers" [-Wincompatible-pointer-types-discards-qualifiers] And replace palloc0+strcpy with pstrdup. Caused by: - d5f139cb6814f0af2d2e1106899361e45c305630 (PostgreSQL) Constify fields and parameters in spell.c Tags: shared_ispell
1 parent 64ee638 commit a11142e

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

src/shared_ispell.c

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ static SegmentInfo *segment_info = NULL;
8080
static void ispell_shmem_startup(void);
8181

8282
static char *shalloc(int bytes);
83-
static char *shstrcpy(char *str);
83+
static char *shstrcpy(const char *str);
8484

8585
static SharedIspellDict *copyIspellDict(IspellDict *dict, char *dictFile, char *affixFile, int bytes, int words);
8686
static SharedStopList *copyStopList(StopList *list, char *stopFile, int bytes);
@@ -346,13 +346,10 @@ init_shared_dict(DictInfo *info, MemoryContext infoCntx,
346346
dict->useFlagAliases = true;
347347
dict->lenAffixData = info->dict.lenAffixData;
348348
dict->nAffixData = info->dict.nAffixData;
349-
dict->AffixData = (char **) palloc0(dict->nAffixData * sizeof(char *));
349+
dict->AffixData = (const char **) palloc0(dict->nAffixData * sizeof(char *));
350350

351351
for (i = 0; i < dict->nAffixData; i++)
352-
{
353-
dict->AffixData[i] = palloc0(strlen(info->dict.AffixData[i]) + 1);
354-
strcpy(dict->AffixData[i], info->dict.AffixData[i]);
355-
}
352+
dict->AffixData[i] = pstrdup(info->dict.AffixData[i]);
356353
}
357354

358355
NISortDictionary(dict);
@@ -709,7 +706,7 @@ shalloc(int bytes)
709706
* by the code that reads and parses the dictionary / affixes).
710707
*/
711708
static char *
712-
shstrcpy(char *str)
709+
shstrcpy(const char *str)
713710
{
714711
char *tmp = shalloc(strlen(str) + 1);
715712

@@ -821,7 +818,7 @@ copyIspellDict(IspellDict *dict, char *dictFile, char *affixFile, int size, int
821818

822819
/* copy affix data */
823820
copy->dict.nAffixData = dict->nAffixData;
824-
copy->dict.AffixData = (char **) shalloc(sizeof(char *) * dict->nAffixData);
821+
copy->dict.AffixData = (const char **) shalloc(sizeof(char *) * dict->nAffixData);
825822
for (i = 0; i < copy->dict.nAffixData; i++)
826823
copy->dict.AffixData[i] = shstrcpy(dict->AffixData[i]);
827824

0 commit comments

Comments
 (0)