Remove unnecessary (char *) casts [string]
authorPeter Eisentraut <peter@eisentraut.org>
Wed, 12 Feb 2025 07:49:18 +0000 (08:49 +0100)
committerPeter Eisentraut <peter@eisentraut.org>
Wed, 12 Feb 2025 07:49:18 +0000 (08:49 +0100)
Remove (char *) casts around string functions where the arguments or
result already have the right type and the cast is useless (or worse,
potentially casts away a qualifier, but this doesn't appear to be the
case here).

Reviewed-by: Dagfinn Ilmari Mannsåker <ilmari@ilmari.org>
Discussion: https://www.postgresql.org/message-id/flat/fd1fcedb-3492-4fc8-9e3e-74b97f2db6c7%40eisentraut.org

contrib/fuzzystrmatch/dmetaphone.c
doc/src/sgml/gist.sgml
src/backend/replication/walreceiver.c
src/backend/replication/walreceiverfuncs.c
src/backend/utils/activity/backend_status.c
src/interfaces/ecpg/pgtypeslib/common.c

index f8f2c2b447d2b1ab1e2c0a32083e96166234e7c3..6627b2b89433acb140b0a57dac28d54179727eb2 100644 (file)
@@ -308,13 +308,13 @@ IsVowel(metastring *s, int pos)
 static int
 SlavoGermanic(metastring *s)
 {
-   if ((char *) strstr(s->str, "W"))
+   if (strstr(s->str, "W"))
        return 1;
-   else if ((char *) strstr(s->str, "K"))
+   else if (strstr(s->str, "K"))
        return 1;
-   else if ((char *) strstr(s->str, "CZ"))
+   else if (strstr(s->str, "CZ"))
        return 1;
-   else if ((char *) strstr(s->str, "WITZ"))
+   else if (strstr(s->str, "WITZ"))
        return 1;
    else
        return 0;
index 99098ab2522831815f9b40d805656328bede09a2..df4afaa2e77b4ab5aa4b2ceec8ae0c7242de9f88 100644 (file)
@@ -1027,7 +1027,7 @@ fill_my_string_relopt(const char *value, void *ptr)
     int     len = strlen(tmp);
 
     if (ptr)
-        strcpy((char *) ptr, tmp);
+        strcpy(ptr, tmp);
 
     pfree(tmp);
     return len + 1;
index 716092f717c3a9ef323fdc2013622640fe754bfa..bd09262e27d198bc528902d2f7f62cd076318849 100644 (file)
@@ -249,8 +249,8 @@ WalReceiverMain(char *startup_data, size_t startup_data_len)
 
    /* Fetch information required to start streaming */
    walrcv->ready_to_display = false;
-   strlcpy(conninfo, (char *) walrcv->conninfo, MAXCONNINFO);
-   strlcpy(slotname, (char *) walrcv->slotname, NAMEDATALEN);
+   strlcpy(conninfo, walrcv->conninfo, MAXCONNINFO);
+   strlcpy(slotname, walrcv->slotname, NAMEDATALEN);
    is_temp_slot = walrcv->is_temp_slot;
    startpoint = walrcv->receiveStart;
    startpointTLI = walrcv->receiveStartTLI;
@@ -317,11 +317,11 @@ WalReceiverMain(char *startup_data, size_t startup_data_len)
    SpinLockAcquire(&walrcv->mutex);
    memset(walrcv->conninfo, 0, MAXCONNINFO);
    if (tmp_conninfo)
-       strlcpy((char *) walrcv->conninfo, tmp_conninfo, MAXCONNINFO);
+       strlcpy(walrcv->conninfo, tmp_conninfo, MAXCONNINFO);
 
    memset(walrcv->sender_host, 0, NI_MAXHOST);
    if (sender_host)
-       strlcpy((char *) walrcv->sender_host, sender_host, NI_MAXHOST);
+       strlcpy(walrcv->sender_host, sender_host, NI_MAXHOST);
 
    walrcv->sender_port = sender_port;
    walrcv->ready_to_display = true;
@@ -1434,10 +1434,10 @@ pg_stat_get_wal_receiver(PG_FUNCTION_ARGS)
    last_receipt_time = WalRcv->lastMsgReceiptTime;
    latest_end_lsn = WalRcv->latestWalEnd;
    latest_end_time = WalRcv->latestWalEndTime;
-   strlcpy(slotname, (char *) WalRcv->slotname, sizeof(slotname));
-   strlcpy(sender_host, (char *) WalRcv->sender_host, sizeof(sender_host));
+   strlcpy(slotname, WalRcv->slotname, sizeof(slotname));
+   strlcpy(sender_host, WalRcv->sender_host, sizeof(sender_host));
    sender_port = WalRcv->sender_port;
-   strlcpy(conninfo, (char *) WalRcv->conninfo, sizeof(conninfo));
+   strlcpy(conninfo, WalRcv->conninfo, sizeof(conninfo));
    SpinLockRelease(&WalRcv->mutex);
 
    /*
index e7eb3ac12a4719c521a1d8ed586d1f08d12d6475..8de2886ff0b59b0909a74a381ac40876598e1ce2 100644 (file)
@@ -267,7 +267,7 @@ RequestXLogStreaming(TimeLineID tli, XLogRecPtr recptr, const char *conninfo,
           walrcv->walRcvState == WALRCV_WAITING);
 
    if (conninfo != NULL)
-       strlcpy((char *) walrcv->conninfo, conninfo, MAXCONNINFO);
+       strlcpy(walrcv->conninfo, conninfo, MAXCONNINFO);
    else
        walrcv->conninfo[0] = '\0';
 
@@ -279,7 +279,7 @@ RequestXLogStreaming(TimeLineID tli, XLogRecPtr recptr, const char *conninfo,
     */
    if (slotname != NULL && slotname[0] != '\0')
    {
-       strlcpy((char *) walrcv->slotname, slotname, NAMEDATALEN);
+       strlcpy(walrcv->slotname, slotname, NAMEDATALEN);
        walrcv->is_temp_slot = false;
    }
    else
index 731342799a62571cf0960be966cad92af3a443dd..ae8e54c744267f80c1802a3a4921406c69b2c4e8 100644 (file)
@@ -795,11 +795,11 @@ pgstat_read_current_status(void)
                 * strcpy is safe even if the string is modified concurrently,
                 * because there's always a \0 at the end of the buffer.
                 */
-               strcpy(localappname, (char *) beentry->st_appname);
+               strcpy(localappname, beentry->st_appname);
                localentry->backendStatus.st_appname = localappname;
-               strcpy(localclienthostname, (char *) beentry->st_clienthostname);
+               strcpy(localclienthostname, beentry->st_clienthostname);
                localentry->backendStatus.st_clienthostname = localclienthostname;
-               strcpy(localactivity, (char *) beentry->st_activity_raw);
+               strcpy(localactivity, beentry->st_activity_raw);
                localentry->backendStatus.st_activity_raw = localactivity;
 #ifdef USE_SSL
                if (beentry->st_ssl)
index 8972229ca2f4097d04746029bb7d4bd02033d105..c9e9a55c6a7266e2eddee71df99c6cd4336023e0 100644 (file)
@@ -19,7 +19,7 @@ pgtypes_alloc(long size)
 char *
 pgtypes_strdup(const char *str)
 {
-   char       *new = (char *) strdup(str);
+   char       *new = strdup(str);
 
    if (!new)
        errno = ENOMEM;