Commit 37d99160 authored by Peter Eisentraut's avatar Peter Eisentraut

More unconstify use

Replace casts whose only purpose is to cast away const with the
unconstify() macro.

Discussion: https://www.postgresql.org/message-id/flat/53a28052-f9f3-1808-fed9-460fd43035ab%402ndquadrant.com
parent cf40dc65
...@@ -185,10 +185,10 @@ gbt_num_union(GBT_NUMKEY *out, const GistEntryVector *entryvec, const gbtree_nin ...@@ -185,10 +185,10 @@ gbt_num_union(GBT_NUMKEY *out, const GistEntryVector *entryvec, const gbtree_nin
c.upper = &cur[tinfo->size]; c.upper = &cur[tinfo->size];
/* if out->lower > cur->lower, adopt cur as lower */ /* if out->lower > cur->lower, adopt cur as lower */
if (tinfo->f_gt(o.lower, c.lower, flinfo)) if (tinfo->f_gt(o.lower, c.lower, flinfo))
memcpy((void *) o.lower, c.lower, tinfo->size); memcpy(unconstify(GBT_NUMKEY *, o.lower), c.lower, tinfo->size);
/* if out->upper < cur->upper, adopt cur as upper */ /* if out->upper < cur->upper, adopt cur as upper */
if (tinfo->f_lt(o.upper, c.upper, flinfo)) if (tinfo->f_lt(o.upper, c.upper, flinfo))
memcpy((void *) o.upper, c.upper, tinfo->size); memcpy(unconstify(GBT_NUMKEY *, o.upper), c.upper, tinfo->size);
} }
return out; return out;
...@@ -237,9 +237,9 @@ gbt_num_bin_union(Datum *u, GBT_NUMKEY *e, const gbtree_ninfo *tinfo, FmgrInfo * ...@@ -237,9 +237,9 @@ gbt_num_bin_union(Datum *u, GBT_NUMKEY *e, const gbtree_ninfo *tinfo, FmgrInfo *
ur.lower = &(((GBT_NUMKEY *) DatumGetPointer(*u))[0]); ur.lower = &(((GBT_NUMKEY *) DatumGetPointer(*u))[0]);
ur.upper = &(((GBT_NUMKEY *) DatumGetPointer(*u))[tinfo->size]); ur.upper = &(((GBT_NUMKEY *) DatumGetPointer(*u))[tinfo->size]);
if (tinfo->f_gt(ur.lower, rd.lower, flinfo)) if (tinfo->f_gt(ur.lower, rd.lower, flinfo))
memcpy((void *) ur.lower, rd.lower, tinfo->size); memcpy(unconstify(GBT_NUMKEY *, ur.lower), rd.lower, tinfo->size);
if (tinfo->f_lt(ur.upper, rd.upper, flinfo)) if (tinfo->f_lt(ur.upper, rd.upper, flinfo))
memcpy((void *) ur.upper, rd.upper, tinfo->size); memcpy(unconstify(GBT_NUMKEY *, ur.upper), rd.upper, tinfo->size);
} }
} }
......
...@@ -2050,7 +2050,7 @@ mp_int_read_cstring(mp_int z, mp_size radix, const char *str, char **end) ...@@ -2050,7 +2050,7 @@ mp_int_read_cstring(mp_int z, mp_size radix, const char *str, char **end)
MP_SIGN(z) = MP_ZPOS; MP_SIGN(z) = MP_ZPOS;
if (end != NULL) if (end != NULL)
*end = (char *) str; *end = unconstify(char *, str);
/* /*
* Return a truncation error if the string has unprocessed characters * Return a truncation error if the string has unprocessed characters
......
...@@ -161,7 +161,7 @@ md5_loop(md5_ctxt *ctxt, const uint8 *input, unsigned len) ...@@ -161,7 +161,7 @@ md5_loop(md5_ctxt *ctxt, const uint8 *input, unsigned len)
md5_calc(ctxt->md5_buf, ctxt); md5_calc(ctxt->md5_buf, ctxt);
for (i = gap; i + MD5_BUFLEN <= len; i += MD5_BUFLEN) for (i = gap; i + MD5_BUFLEN <= len; i += MD5_BUFLEN)
md5_calc((uint8 *) (input + i), ctxt); md5_calc(unconstify(uint8 *, (input + i)), ctxt);
ctxt->md5_i = len - i; ctxt->md5_i = len - i;
memmove(ctxt->md5_buf, input + i, ctxt->md5_i); memmove(ctxt->md5_buf, input + i, ctxt->md5_i);
......
...@@ -117,7 +117,7 @@ compress_process(PushFilter *next, void *priv, const uint8 *data, int len) ...@@ -117,7 +117,7 @@ compress_process(PushFilter *next, void *priv, const uint8 *data, int len)
*/ */
while (len > 0) while (len > 0)
{ {
st->stream.next_in = (void *) data; st->stream.next_in = unconstify(uint8 *, data);
st->stream.avail_in = len; st->stream.avail_in = len;
st->stream.next_out = st->buf; st->stream.next_out = st->buf;
st->stream.avail_out = st->buf_len; st->stream.avail_out = st->buf_len;
......
...@@ -178,7 +178,7 @@ brin_doupdate(Relation idxrel, BlockNumber pagesPerRange, ...@@ -178,7 +178,7 @@ brin_doupdate(Relation idxrel, BlockNumber pagesPerRange,
brin_can_do_samepage_update(oldbuf, origsz, newsz)) brin_can_do_samepage_update(oldbuf, origsz, newsz))
{ {
START_CRIT_SECTION(); START_CRIT_SECTION();
if (!PageIndexTupleOverwrite(oldpage, oldoff, (Item) newtup, newsz)) if (!PageIndexTupleOverwrite(oldpage, oldoff, (Item) unconstify(BrinTuple *, newtup), newsz))
elog(ERROR, "failed to replace BRIN tuple"); elog(ERROR, "failed to replace BRIN tuple");
MarkBufferDirty(oldbuf); MarkBufferDirty(oldbuf);
...@@ -195,7 +195,7 @@ brin_doupdate(Relation idxrel, BlockNumber pagesPerRange, ...@@ -195,7 +195,7 @@ brin_doupdate(Relation idxrel, BlockNumber pagesPerRange,
XLogRegisterData((char *) &xlrec, SizeOfBrinSamepageUpdate); XLogRegisterData((char *) &xlrec, SizeOfBrinSamepageUpdate);
XLogRegisterBuffer(0, oldbuf, REGBUF_STANDARD); XLogRegisterBuffer(0, oldbuf, REGBUF_STANDARD);
XLogRegisterBufData(0, (char *) newtup, newsz); XLogRegisterBufData(0, (char *) unconstify(BrinTuple *, newtup), newsz);
recptr = XLogInsert(RM_BRIN_ID, info); recptr = XLogInsert(RM_BRIN_ID, info);
...@@ -252,7 +252,7 @@ brin_doupdate(Relation idxrel, BlockNumber pagesPerRange, ...@@ -252,7 +252,7 @@ brin_doupdate(Relation idxrel, BlockNumber pagesPerRange,
brin_page_init(newpage, BRIN_PAGETYPE_REGULAR); brin_page_init(newpage, BRIN_PAGETYPE_REGULAR);
PageIndexTupleDeleteNoCompact(oldpage, oldoff); PageIndexTupleDeleteNoCompact(oldpage, oldoff);
newoff = PageAddItem(newpage, (Item) newtup, newsz, newoff = PageAddItem(newpage, (Item) unconstify(BrinTuple *, newtup), newsz,
InvalidOffsetNumber, false, false); InvalidOffsetNumber, false, false);
if (newoff == InvalidOffsetNumber) if (newoff == InvalidOffsetNumber)
elog(ERROR, "failed to add BRIN tuple to new page"); elog(ERROR, "failed to add BRIN tuple to new page");
...@@ -287,7 +287,7 @@ brin_doupdate(Relation idxrel, BlockNumber pagesPerRange, ...@@ -287,7 +287,7 @@ brin_doupdate(Relation idxrel, BlockNumber pagesPerRange,
XLogRegisterData((char *) &xlrec, SizeOfBrinUpdate); XLogRegisterData((char *) &xlrec, SizeOfBrinUpdate);
XLogRegisterBuffer(0, newbuf, REGBUF_STANDARD | (extended ? REGBUF_WILL_INIT : 0)); XLogRegisterBuffer(0, newbuf, REGBUF_STANDARD | (extended ? REGBUF_WILL_INIT : 0));
XLogRegisterBufData(0, (char *) newtup, newsz); XLogRegisterBufData(0, (char *) unconstify(BrinTuple *, newtup), newsz);
/* revmap page */ /* revmap page */
XLogRegisterBuffer(1, revmapbuf, 0); XLogRegisterBuffer(1, revmapbuf, 0);
......
...@@ -5409,7 +5409,7 @@ XactLogCommitRecord(TimestampTz commit_time, ...@@ -5409,7 +5409,7 @@ XactLogCommitRecord(TimestampTz commit_time,
{ {
XLogRegisterData((char *) (&xl_twophase), sizeof(xl_xact_twophase)); XLogRegisterData((char *) (&xl_twophase), sizeof(xl_xact_twophase));
if (xl_xinfo.xinfo & XACT_XINFO_HAS_GID) if (xl_xinfo.xinfo & XACT_XINFO_HAS_GID)
XLogRegisterData((char *) twophase_gid, strlen(twophase_gid) + 1); XLogRegisterData(unconstify(char *, twophase_gid), strlen(twophase_gid) + 1);
} }
if (xl_xinfo.xinfo & XACT_XINFO_HAS_ORIGIN) if (xl_xinfo.xinfo & XACT_XINFO_HAS_ORIGIN)
...@@ -5537,7 +5537,7 @@ XactLogAbortRecord(TimestampTz abort_time, ...@@ -5537,7 +5537,7 @@ XactLogAbortRecord(TimestampTz abort_time,
{ {
XLogRegisterData((char *) (&xl_twophase), sizeof(xl_xact_twophase)); XLogRegisterData((char *) (&xl_twophase), sizeof(xl_xact_twophase));
if (xl_xinfo.xinfo & XACT_XINFO_HAS_GID) if (xl_xinfo.xinfo & XACT_XINFO_HAS_GID)
XLogRegisterData((char *) twophase_gid, strlen(twophase_gid) + 1); XLogRegisterData(unconstify(char *, twophase_gid), strlen(twophase_gid) + 1);
} }
if (xl_xinfo.xinfo & XACT_XINFO_HAS_ORIGIN) if (xl_xinfo.xinfo & XACT_XINFO_HAS_ORIGIN)
......
...@@ -1314,7 +1314,7 @@ SPI_cursor_open_internal(const char *name, SPIPlanPtr plan, ...@@ -1314,7 +1314,7 @@ SPI_cursor_open_internal(const char *name, SPIPlanPtr plan,
* throws an error. * throws an error.
*/ */
spierrcontext.callback = _SPI_error_callback; spierrcontext.callback = _SPI_error_callback;
spierrcontext.arg = (void *) plansource->query_string; spierrcontext.arg = unconstify(char *, plansource->query_string);
spierrcontext.previous = error_context_stack; spierrcontext.previous = error_context_stack;
error_context_stack = &spierrcontext; error_context_stack = &spierrcontext;
...@@ -1753,7 +1753,7 @@ SPI_plan_get_cached_plan(SPIPlanPtr plan) ...@@ -1753,7 +1753,7 @@ SPI_plan_get_cached_plan(SPIPlanPtr plan)
/* Setup error traceback support for ereport() */ /* Setup error traceback support for ereport() */
spierrcontext.callback = _SPI_error_callback; spierrcontext.callback = _SPI_error_callback;
spierrcontext.arg = (void *) plansource->query_string; spierrcontext.arg = unconstify(char *, plansource->query_string);
spierrcontext.previous = error_context_stack; spierrcontext.previous = error_context_stack;
error_context_stack = &spierrcontext; error_context_stack = &spierrcontext;
...@@ -1884,7 +1884,7 @@ _SPI_prepare_plan(const char *src, SPIPlanPtr plan) ...@@ -1884,7 +1884,7 @@ _SPI_prepare_plan(const char *src, SPIPlanPtr plan)
* Setup error traceback support for ereport() * Setup error traceback support for ereport()
*/ */
spierrcontext.callback = _SPI_error_callback; spierrcontext.callback = _SPI_error_callback;
spierrcontext.arg = (void *) src; spierrcontext.arg = unconstify(char *, src);
spierrcontext.previous = error_context_stack; spierrcontext.previous = error_context_stack;
error_context_stack = &spierrcontext; error_context_stack = &spierrcontext;
...@@ -1989,7 +1989,7 @@ _SPI_prepare_oneshot_plan(const char *src, SPIPlanPtr plan) ...@@ -1989,7 +1989,7 @@ _SPI_prepare_oneshot_plan(const char *src, SPIPlanPtr plan)
* Setup error traceback support for ereport() * Setup error traceback support for ereport()
*/ */
spierrcontext.callback = _SPI_error_callback; spierrcontext.callback = _SPI_error_callback;
spierrcontext.arg = (void *) src; spierrcontext.arg = unconstify(char *, src);
spierrcontext.previous = error_context_stack; spierrcontext.previous = error_context_stack;
error_context_stack = &spierrcontext; error_context_stack = &spierrcontext;
...@@ -2100,7 +2100,7 @@ _SPI_execute_plan(SPIPlanPtr plan, ParamListInfo paramLI, ...@@ -2100,7 +2100,7 @@ _SPI_execute_plan(SPIPlanPtr plan, ParamListInfo paramLI,
List *stmt_list; List *stmt_list;
ListCell *lc2; ListCell *lc2;
spierrcontext.arg = (void *) plansource->query_string; spierrcontext.arg = unconstify(char *, plansource->query_string);
/* /*
* If this is a one-shot plan, we still need to do parse analysis. * If this is a one-shot plan, we still need to do parse analysis.
......
...@@ -867,7 +867,7 @@ CheckSCRAMAuth(Port *port, char *shadow_pass, char **logdetail) ...@@ -867,7 +867,7 @@ CheckSCRAMAuth(Port *port, char *shadow_pass, char **logdetail)
void *scram_opaq = NULL; void *scram_opaq = NULL;
char *output = NULL; char *output = NULL;
int outputlen = 0; int outputlen = 0;
char *input; const char *input;
int inputlen; int inputlen;
int result; int result;
bool initial; bool initial;
...@@ -964,14 +964,14 @@ CheckSCRAMAuth(Port *port, char *shadow_pass, char **logdetail) ...@@ -964,14 +964,14 @@ CheckSCRAMAuth(Port *port, char *shadow_pass, char **logdetail)
if (inputlen == -1) if (inputlen == -1)
input = NULL; input = NULL;
else else
input = (char *) pq_getmsgbytes(&buf, inputlen); input = pq_getmsgbytes(&buf, inputlen);
initial = false; initial = false;
} }
else else
{ {
inputlen = buf.len; inputlen = buf.len;
input = (char *) pq_getmsgbytes(&buf, buf.len); input = pq_getmsgbytes(&buf, buf.len);
} }
pq_getmsgend(&buf); pq_getmsgend(&buf);
...@@ -985,7 +985,7 @@ CheckSCRAMAuth(Port *port, char *shadow_pass, char **logdetail) ...@@ -985,7 +985,7 @@ CheckSCRAMAuth(Port *port, char *shadow_pass, char **logdetail)
* we pass 'logdetail' as NULL when doing a mock authentication, * we pass 'logdetail' as NULL when doing a mock authentication,
* because we should already have a better error message in that case * because we should already have a better error message in that case
*/ */
result = pg_be_scram_exchange(scram_opaq, input, inputlen, result = pg_be_scram_exchange(scram_opaq, unconstify(char *, input), inputlen,
&output, &outputlen, &output, &outputlen,
logdetail); logdetail);
...@@ -2175,7 +2175,7 @@ CheckPAMAuth(Port *port, const char *user, const char *password) ...@@ -2175,7 +2175,7 @@ CheckPAMAuth(Port *port, const char *user, const char *password)
* later used inside the PAM conversation to pass the password to the * later used inside the PAM conversation to pass the password to the
* authentication module. * authentication module.
*/ */
pam_passw_conv.appdata_ptr = (char *) password; /* from password above, pam_passw_conv.appdata_ptr = unconstify(char *, password); /* from password above,
* not allocated */ * not allocated */
/* Optionally, one can set the service name in pg_hba.conf */ /* Optionally, one can set the service name in pg_hba.conf */
......
...@@ -866,7 +866,7 @@ load_dh_buffer(const char *buffer, size_t len) ...@@ -866,7 +866,7 @@ load_dh_buffer(const char *buffer, size_t len)
BIO *bio; BIO *bio;
DH *dh = NULL; DH *dh = NULL;
bio = BIO_new_mem_buf((char *) buffer, len); bio = BIO_new_mem_buf(unconstify(char *, buffer), len);
if (bio == NULL) if (bio == NULL)
return NULL; return NULL;
dh = PEM_read_bio_DHparams(bio, NULL, NULL, NULL); dh = PEM_read_bio_DHparams(bio, NULL, NULL, NULL);
......
...@@ -739,7 +739,7 @@ typeStringToTypeName(const char *str) ...@@ -739,7 +739,7 @@ typeStringToTypeName(const char *str)
* Setup error traceback support in case of ereport() during parse * Setup error traceback support in case of ereport() during parse
*/ */
ptserrcontext.callback = pts_error_callback; ptserrcontext.callback = pts_error_callback;
ptserrcontext.arg = (void *) str; ptserrcontext.arg = unconstify(char *, str);
ptserrcontext.previous = error_context_stack; ptserrcontext.previous = error_context_stack;
error_context_stack = &ptserrcontext; error_context_stack = &ptserrcontext;
......
...@@ -69,8 +69,8 @@ LogLogicalMessage(const char *prefix, const char *message, size_t size, ...@@ -69,8 +69,8 @@ LogLogicalMessage(const char *prefix, const char *message, size_t size,
XLogBeginInsert(); XLogBeginInsert();
XLogRegisterData((char *) &xlrec, SizeOfLogicalMessage); XLogRegisterData((char *) &xlrec, SizeOfLogicalMessage);
XLogRegisterData((char *) prefix, xlrec.prefix_size); XLogRegisterData(unconstify(char *, prefix), xlrec.prefix_size);
XLogRegisterData((char *) message, size); XLogRegisterData(unconstify(char *, message), size);
/* allow origin filtering */ /* allow origin filtering */
XLogSetRecordFlags(XLOG_INCLUDE_ORIGIN); XLogSetRecordFlags(XLOG_INCLUDE_ORIGIN);
......
...@@ -1767,7 +1767,7 @@ exec_bind_message(StringInfo input_message) ...@@ -1767,7 +1767,7 @@ exec_bind_message(StringInfo input_message)
* trailing null. This is grotty but is a big win when * trailing null. This is grotty but is a big win when
* dealing with very large parameter strings. * dealing with very large parameter strings.
*/ */
pbuf.data = (char *) pvalue; pbuf.data = unconstify(char *, pvalue);
pbuf.maxlen = plength + 1; pbuf.maxlen = plength + 1;
pbuf.len = plength; pbuf.len = plength;
pbuf.cursor = 0; pbuf.cursor = 0;
......
...@@ -3688,7 +3688,7 @@ to_timestamp(PG_FUNCTION_ARGS) ...@@ -3688,7 +3688,7 @@ to_timestamp(PG_FUNCTION_ARGS)
/* Use the specified time zone, if any. */ /* Use the specified time zone, if any. */
if (tm.tm_zone) if (tm.tm_zone)
{ {
int dterr = DecodeTimezone((char *) tm.tm_zone, &tz); int dterr = DecodeTimezone(unconstify(char *, tm.tm_zone), &tz);
if (dterr) if (dterr)
DateTimeParseError(dterr, text_to_cstring(date_txt), "timestamptz"); DateTimeParseError(dterr, text_to_cstring(date_txt), "timestamptz");
......
...@@ -464,7 +464,7 @@ pg_convert(PG_FUNCTION_ARGS) ...@@ -464,7 +464,7 @@ pg_convert(PG_FUNCTION_ARGS)
pg_verify_mbstr_len(src_encoding, src_str, len, false); pg_verify_mbstr_len(src_encoding, src_str, len, false);
/* perform conversion */ /* perform conversion */
dest_str = (char *) pg_do_encoding_conversion((unsigned char *) src_str, dest_str = (char *) pg_do_encoding_conversion((unsigned char *) unconstify(char *, src_str),
len, len,
src_encoding, src_encoding,
dest_encoding); dest_encoding);
...@@ -561,7 +561,7 @@ char * ...@@ -561,7 +561,7 @@ char *
pg_any_to_server(const char *s, int len, int encoding) pg_any_to_server(const char *s, int len, int encoding)
{ {
if (len <= 0) if (len <= 0)
return (char *) s; /* empty string is always valid */ return unconstify(char *, s); /* empty string is always valid */
if (encoding == DatabaseEncoding->encoding || if (encoding == DatabaseEncoding->encoding ||
encoding == PG_SQL_ASCII) encoding == PG_SQL_ASCII)
...@@ -570,7 +570,7 @@ pg_any_to_server(const char *s, int len, int encoding) ...@@ -570,7 +570,7 @@ pg_any_to_server(const char *s, int len, int encoding)
* No conversion is needed, but we must still validate the data. * No conversion is needed, but we must still validate the data.
*/ */
(void) pg_verify_mbstr(DatabaseEncoding->encoding, s, len, false); (void) pg_verify_mbstr(DatabaseEncoding->encoding, s, len, false);
return (char *) s; return unconstify(char *, s);
} }
if (DatabaseEncoding->encoding == PG_SQL_ASCII) if (DatabaseEncoding->encoding == PG_SQL_ASCII)
...@@ -600,7 +600,7 @@ pg_any_to_server(const char *s, int len, int encoding) ...@@ -600,7 +600,7 @@ pg_any_to_server(const char *s, int len, int encoding)
(unsigned char) s[i]))); (unsigned char) s[i])));
} }
} }
return (char *) s; return unconstify(char *, s);
} }
/* Fast path if we can use cached conversion function */ /* Fast path if we can use cached conversion function */
...@@ -608,7 +608,7 @@ pg_any_to_server(const char *s, int len, int encoding) ...@@ -608,7 +608,7 @@ pg_any_to_server(const char *s, int len, int encoding)
return perform_default_encoding_conversion(s, len, true); return perform_default_encoding_conversion(s, len, true);
/* General case ... will not work outside transactions */ /* General case ... will not work outside transactions */
return (char *) pg_do_encoding_conversion((unsigned char *) s, return (char *) pg_do_encoding_conversion((unsigned char *) unconstify(char *, s),
len, len,
encoding, encoding,
DatabaseEncoding->encoding); DatabaseEncoding->encoding);
...@@ -634,17 +634,17 @@ char * ...@@ -634,17 +634,17 @@ char *
pg_server_to_any(const char *s, int len, int encoding) pg_server_to_any(const char *s, int len, int encoding)
{ {
if (len <= 0) if (len <= 0)
return (char *) s; /* empty string is always valid */ return unconstify(char *, s); /* empty string is always valid */
if (encoding == DatabaseEncoding->encoding || if (encoding == DatabaseEncoding->encoding ||
encoding == PG_SQL_ASCII) encoding == PG_SQL_ASCII)
return (char *) s; /* assume data is valid */ return unconstify(char *, s); /* assume data is valid */
if (DatabaseEncoding->encoding == PG_SQL_ASCII) if (DatabaseEncoding->encoding == PG_SQL_ASCII)
{ {
/* No conversion is possible, but we must validate the result */ /* No conversion is possible, but we must validate the result */
(void) pg_verify_mbstr(encoding, s, len, false); (void) pg_verify_mbstr(encoding, s, len, false);
return (char *) s; return unconstify(char *, s);
} }
/* Fast path if we can use cached conversion function */ /* Fast path if we can use cached conversion function */
...@@ -652,7 +652,7 @@ pg_server_to_any(const char *s, int len, int encoding) ...@@ -652,7 +652,7 @@ pg_server_to_any(const char *s, int len, int encoding)
return perform_default_encoding_conversion(s, len, false); return perform_default_encoding_conversion(s, len, false);
/* General case ... will not work outside transactions */ /* General case ... will not work outside transactions */
return (char *) pg_do_encoding_conversion((unsigned char *) s, return (char *) pg_do_encoding_conversion((unsigned char *) unconstify(char *, s),
len, len,
DatabaseEncoding->encoding, DatabaseEncoding->encoding,
encoding); encoding);
...@@ -687,7 +687,7 @@ perform_default_encoding_conversion(const char *src, int len, ...@@ -687,7 +687,7 @@ perform_default_encoding_conversion(const char *src, int len,
} }
if (flinfo == NULL) if (flinfo == NULL)
return (char *) src; return unconstify(char *, src);
/* /*
* Allocate space for conversion result, being wary of integer overflow * Allocate space for conversion result, being wary of integer overflow
......
...@@ -4897,7 +4897,7 @@ add_placeholder_variable(const char *name, int elevel) ...@@ -4897,7 +4897,7 @@ add_placeholder_variable(const char *name, int elevel)
if (!add_guc_variable((struct config_generic *) var, elevel)) if (!add_guc_variable((struct config_generic *) var, elevel))
{ {
free((void *) gen->name); free(unconstify(char *, gen->name));
free(var); free(var);
return NULL; return NULL;
} }
......
...@@ -1970,7 +1970,7 @@ BaseBackup(void) ...@@ -1970,7 +1970,7 @@ BaseBackup(void)
*/ */
if (format == 'p' && !PQgetisnull(res, i, 1)) if (format == 'p' && !PQgetisnull(res, i, 1))
{ {
char *path = (char *) get_tablespace_mapping(PQgetvalue(res, i, 1)); char *path = unconstify(char *, get_tablespace_mapping(PQgetvalue(res, i, 1)));
verify_dir_is_empty_or_create(path, &made_tablespace_dirs, &found_tablespace_dirs); verify_dir_is_empty_or_create(path, &made_tablespace_dirs, &found_tablespace_dirs);
} }
......
...@@ -496,7 +496,7 @@ tar_write(Walfile f, const void *buf, size_t count) ...@@ -496,7 +496,7 @@ tar_write(Walfile f, const void *buf, size_t count)
#ifdef HAVE_LIBZ #ifdef HAVE_LIBZ
else else
{ {
if (!tar_write_compressed_data((void *) buf, count, false)) if (!tar_write_compressed_data(unconstify(void *, buf), count, false))
return -1; return -1;
((TarMethodFile *) f)->currpos += count; ((TarMethodFile *) f)->currpos += count;
return count; return count;
......
...@@ -312,7 +312,7 @@ static void ...@@ -312,7 +312,7 @@ static void
WriteDataToArchiveZlib(ArchiveHandle *AH, CompressorState *cs, WriteDataToArchiveZlib(ArchiveHandle *AH, CompressorState *cs,
const char *data, size_t dLen) const char *data, size_t dLen)
{ {
cs->zp->next_in = (void *) data; cs->zp->next_in = (void *) unconstify(char *, data);
cs->zp->avail_in = dLen; cs->zp->avail_in = dLen;
DeflateCompressorZlib(AH, cs, false); DeflateCompressorZlib(AH, cs, false);
......
...@@ -181,7 +181,7 @@ get_prompt(promptStatus_t status, ConditionalStack cstack) ...@@ -181,7 +181,7 @@ get_prompt(promptStatus_t status, ConditionalStack cstack)
case '5': case '5':
case '6': case '6':
case '7': case '7':
*buf = (char) strtol(p, (char **) &p, 8); *buf = (char) strtol(p, unconstify(char **, &p), 8);
--p; --p;
break; break;
case 'R': case 'R':
......
...@@ -3250,7 +3250,7 @@ printTableCleanup(printTableContent *const content) ...@@ -3250,7 +3250,7 @@ printTableCleanup(printTableContent *const content)
for (i = 0; i < content->nrows * content->ncolumns; i++) for (i = 0; i < content->nrows * content->ncolumns; i++)
{ {
if (content->cellmustfree[i]) if (content->cellmustfree[i])
free((char *) content->cells[i]); free(unconstify(char *, content->cells[i]));
} }
free(content->cellmustfree); free(content->cellmustfree);
content->cellmustfree = NULL; content->cellmustfree = NULL;
......
...@@ -341,7 +341,7 @@ lo_write(PGconn *conn, int fd, const char *buf, size_t len) ...@@ -341,7 +341,7 @@ lo_write(PGconn *conn, int fd, const char *buf, size_t len)
argv[1].isint = 0; argv[1].isint = 0;
argv[1].len = (int) len; argv[1].len = (int) len;
argv[1].u.ptr = (int *) buf; argv[1].u.ptr = (int *) unconstify(char *, buf);
res = PQfn(conn, conn->lobjfuncs->fn_lo_write, res = PQfn(conn, conn->lobjfuncs->fn_lo_write,
&retval, &result_len, 1, argv, 2); &retval, &result_len, 1, argv, 2);
......
...@@ -36,6 +36,8 @@ ...@@ -36,6 +36,8 @@
/* All "broken" PQExpBuffers point to this string. */ /* All "broken" PQExpBuffers point to this string. */
static const char oom_buffer[1] = ""; static const char oom_buffer[1] = "";
/* Need a char * for unconstify() compatiblity */
static const char * oom_buffer_ptr = oom_buffer;
static bool appendPQExpBufferVA(PQExpBuffer str, const char *fmt, va_list args) pg_attribute_printf(2, 0); static bool appendPQExpBufferVA(PQExpBuffer str, const char *fmt, va_list args) pg_attribute_printf(2, 0);
...@@ -57,7 +59,7 @@ markPQExpBufferBroken(PQExpBuffer str) ...@@ -57,7 +59,7 @@ markPQExpBufferBroken(PQExpBuffer str)
* to put oom_buffer in read-only storage, so that anyone who tries to * to put oom_buffer in read-only storage, so that anyone who tries to
* scribble on a broken PQExpBuffer will get a failure. * scribble on a broken PQExpBuffer will get a failure.
*/ */
str->data = (char *) oom_buffer; str->data = unconstify(char *, oom_buffer_ptr);
str->len = 0; str->len = 0;
str->maxlen = 0; str->maxlen = 0;
} }
...@@ -91,7 +93,7 @@ initPQExpBuffer(PQExpBuffer str) ...@@ -91,7 +93,7 @@ initPQExpBuffer(PQExpBuffer str)
str->data = (char *) malloc(INITIAL_EXPBUFFER_SIZE); str->data = (char *) malloc(INITIAL_EXPBUFFER_SIZE);
if (str->data == NULL) if (str->data == NULL)
{ {
str->data = (char *) oom_buffer; /* see comment above */ str->data = unconstify(char *, oom_buffer_ptr); /* see comment above */
str->maxlen = 0; str->maxlen = 0;
str->len = 0; str->len = 0;
} }
...@@ -130,7 +132,7 @@ termPQExpBuffer(PQExpBuffer str) ...@@ -130,7 +132,7 @@ termPQExpBuffer(PQExpBuffer str)
if (str->data != oom_buffer) if (str->data != oom_buffer)
free(str->data); free(str->data);
/* just for luck, make the buffer validly empty. */ /* just for luck, make the buffer validly empty. */
str->data = (char *) oom_buffer; /* see comment above */ str->data = unconstify(char *, oom_buffer_ptr); /* see comment above */
str->maxlen = 0; str->maxlen = 0;
str->len = 0; str->len = 0;
} }
......
...@@ -610,7 +610,7 @@ call_pltcl_start_proc(Oid prolang, bool pltrusted) ...@@ -610,7 +610,7 @@ call_pltcl_start_proc(Oid prolang, bool pltrusted)
/* Set up errcontext callback to make errors more helpful */ /* Set up errcontext callback to make errors more helpful */
errcallback.callback = start_proc_error_callback; errcallback.callback = start_proc_error_callback;
errcallback.arg = (void *) gucname; errcallback.arg = unconstify(char *, gucname);
errcallback.previous = error_context_stack; errcallback.previous = error_context_stack;
error_context_stack = &errcallback; error_context_stack = &errcallback;
...@@ -3081,7 +3081,7 @@ pltcl_set_tuple_values(Tcl_Interp *interp, const char *arrayname, ...@@ -3081,7 +3081,7 @@ pltcl_set_tuple_values(Tcl_Interp *interp, const char *arrayname,
else else
Tcl_UnsetVar2(interp, *arrptr, *nameptr, 0); Tcl_UnsetVar2(interp, *arrptr, *nameptr, 0);
pfree((char *) attname); pfree(unconstify(char *, attname));
} }
} }
......
...@@ -106,7 +106,7 @@ first_dir_separator(const char *filename) ...@@ -106,7 +106,7 @@ first_dir_separator(const char *filename)
for (p = skip_drive(filename); *p; p++) for (p = skip_drive(filename); *p; p++)
if (IS_DIR_SEP(*p)) if (IS_DIR_SEP(*p))
return (char *) p; return unconstify(char *, p);
return NULL; return NULL;
} }
...@@ -124,7 +124,7 @@ first_path_var_separator(const char *pathlist) ...@@ -124,7 +124,7 @@ first_path_var_separator(const char *pathlist)
/* skip_drive is not needed */ /* skip_drive is not needed */
for (p = pathlist; *p; p++) for (p = pathlist; *p; p++)
if (IS_PATH_VAR_SEP(*p)) if (IS_PATH_VAR_SEP(*p))
return (char *) p; return unconstify(char *, p);
return NULL; return NULL;
} }
...@@ -143,7 +143,7 @@ last_dir_separator(const char *filename) ...@@ -143,7 +143,7 @@ last_dir_separator(const char *filename)
for (p = skip_drive(filename); *p; p++) for (p = skip_drive(filename); *p; p++)
if (IS_DIR_SEP(*p)) if (IS_DIR_SEP(*p))
ret = p; ret = p;
return (char *) ret; return unconstify(char *, ret);
} }
......
...@@ -1364,7 +1364,7 @@ localsub(struct state const *sp, pg_time_t const *timep, ...@@ -1364,7 +1364,7 @@ localsub(struct state const *sp, pg_time_t const *timep,
if (result) if (result)
{ {
result->tm_isdst = ttisp->tt_isdst; result->tm_isdst = ttisp->tt_isdst;
result->tm_zone = (char *) &sp->chars[ttisp->tt_abbrind]; result->tm_zone = unconstify(char *, &sp->chars[ttisp->tt_abbrind]);
} }
return result; return result;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment