From 31e0fa41211a37bca456568d5df3ab095509633f Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Mon, 21 Nov 2022 06:18:27 +0200 Subject: [PATCH 22/22] fc_utf8.c: Do not cast 'const' away See osdn #45259 Signed-off-by: Marko Lindqvist --- utility/fc_utf8.c | 16 +++++++++------- utility/fc_utf8.h | 7 ++++--- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/utility/fc_utf8.c b/utility/fc_utf8.c index 726efa4180..f62edc50d1 100644 --- a/utility/fc_utf8.c +++ b/utility/fc_utf8.c @@ -92,7 +92,7 @@ static inline bool base_fc_utf8_char_validate(const char *utf8_char, if (1 < size) { do { utf8_char++; - if (0x80 != (0xC0 & *(unsigned char *) utf8_char)) { + if (0x80 != (0xC0 & *(const unsigned char *)utf8_char)) { /* Not a valid byte of the sequence. */ return FALSE; } @@ -203,14 +203,15 @@ bool fc_utf8_char_validate(const char *utf8_char) NB: This function can return a invalid UTF-8 character. Check with fc_utf8_char_validate() to ensure. ****************************************************************************/ -char *fc_utf8_find_next_char(const char *utf8_char) +const char *fc_utf8_find_next_char(const char *utf8_char) { fc_assert_ret_val(NULL != utf8_char, NULL); do { utf8_char++; } while (0 == FC_UTF8_CHAR_SIZE(utf8_char)); - return (char *) utf8_char; + + return utf8_char; } /************************************************************************//** @@ -220,18 +221,19 @@ char *fc_utf8_find_next_char(const char *utf8_char) NB: This function can return a invalid UTF-8 character. Check with fc_utf8_char_validate() to ensure. ****************************************************************************/ -char *fc_utf8_find_prev_char(const char *utf8_char, const char *utf8_string) +const char *fc_utf8_find_prev_char(const char *utf8_char, + const char *utf8_string) { fc_assert_ret_val(NULL != utf8_char, NULL); for (utf8_char--; utf8_char > utf8_string; utf8_char--) { if (0 != FC_UTF8_CHAR_SIZE(utf8_char)) { - return (char *) utf8_char; + return utf8_char; } } - return (char *) utf8_string; -} + return utf8_string; +} /************************************************************************//** Returns TRUE if the string 'utf8_string' contains only valid UTF-8 diff --git a/utility/fc_utf8.h b/utility/fc_utf8.h index a264ad7dce..d6e21c5b51 100644 --- a/utility/fc_utf8.h +++ b/utility/fc_utf8.h @@ -1,4 +1,4 @@ -/********************************************************************** +/*********************************************************************** Freeciv - Copyright (C) 1996 - A Kjeldberg, L Gregersen, P Unold This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -33,9 +33,10 @@ extern const char fc_utf8_skip[256]; /* UTF-8 character functions. */ bool fc_utf8_char_validate(const char *utf8_char) fc__attribute((nonnull (1))); -char *fc_utf8_find_next_char(const char *utf8_char) +const char *fc_utf8_find_next_char(const char *utf8_char) fc__attribute((nonnull (1))); -char *fc_utf8_find_prev_char(const char *utf8_char, const char *utf8_string) +const char *fc_utf8_find_prev_char(const char *utf8_char, + const char *utf8_string) fc__attribute((nonnull (1, 2))); /* Jump to next UTF-8 character, assuming it is a valid UTF-8 string. */ #define fc_ut8_next_char(utf8_char) \ -- 2.35.1