From af1799c0824bbe7bcf6834382c66abbf55c4d88e Mon Sep 17 00:00:00 2001 From: Peter Eisentraut Date: Tue, 10 Nov 2026 08:21:02 +0100 Subject: [PATCH v2 07/11] Fix -Wcast-qual warnings in psql Some platforms declare HIST_ENTRY.line as const char * (apparently macOS and NetBSD libedit), but we cast that away using (char *) and write into it. To appease -Wcast-qual, change that cast to unconstify(). But for other platforms where it is plain char * to begin with, unconstify doesn't work because it doesn't allow casting a non-const to a non-const. So to make this work portably we first have to cast to (const char *). (Maybe we could make unconstify handle this, but so far it is only required in this one place, so it might not be worth it.) Reported-by: Chao Li Discussion: https://www.postgresql.org/message-id/flat/70b86618-4038-4b19-8847-1a400d99d477%40eisentraut.org --- src/bin/psql/input.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/bin/psql/input.c b/src/bin/psql/input.c index 6d37359fc96..76b479387b1 100644 --- a/src/bin/psql/input.c +++ b/src/bin/psql/input.c @@ -303,7 +303,7 @@ encode_history(void) char *cur_ptr; /* some platforms declare HIST_ENTRY.line as const char * */ - for (cur_ptr = (char *) cur_hist->line; *cur_ptr; cur_ptr++) + for (cur_ptr = unconstify(char *, (const char *) cur_hist->line); *cur_ptr; cur_ptr++) { if (*cur_ptr == '\n') *cur_ptr = NL_IN_HISTORY; @@ -323,7 +323,7 @@ decode_history(void) char *cur_ptr; /* some platforms declare HIST_ENTRY.line as const char * */ - for (cur_ptr = (char *) cur_hist->line; *cur_ptr; cur_ptr++) + for (cur_ptr = unconstify(char *, (const char *) cur_hist->line); *cur_ptr; cur_ptr++) { if (*cur_ptr == NL_IN_HISTORY) *cur_ptr = '\n'; -- 2.56.0