Fix GCC warnings by using const pointers for strchr/memchr results (#15108)

### Problem


On Ubuntu 26.04, running `make test` shows these GCC warnings:
```shell
resp_parser.c: In function ‘parseBulk’:
resp_parser.c:44:15: warning: initialization discards ‘const’ qualifier from pointer target type [-Wdiscarded-qualifiers]
   44 |     char *p = strchr(proto+1,'\r');
      |               ^~~~~~
resp_parser.c: In function ‘parseSimpleString’:
resp_parser.c:63:15: warning: initialization discards ‘const’ qualifier from pointer target type [-Wdiscarded-qualifiers]
   63 |     char *p = strchr(proto+1,'\r');
      |               ^~~~~~
resp_parser.c: In function ‘parseError’:
resp_parser.c:71:15: warning: initialization discards ‘const’ qualifier from pointer target type [-Wdiscarded-qualifiers]
   71 |     char *p = strchr(proto+1,'\r');
      |               ^~~~~~
resp_parser.c: In function ‘parseLong’:
resp_parser.c:79:15: warning: initialization discards ‘const’ qualifier from pointer target type [-Wdiscarded-qualifiers]
   79 |     char *p = strchr(proto+1,'\r');
      |               ^~~~~~
```

### Changed

It updates local pointer types from `char *` to `const char *` without
changing runtime behavior.
This commit is contained in:
Vitah Lin 2026-06-05 15:52:43 +08:00 committed by GitHub
parent c0c014036b
commit 894a225ffa
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 16 additions and 16 deletions

View file

@ -92,7 +92,7 @@ static uint64_t keyMetaClassEncode(const char *name, int metaver, uint64_t flags
/* Encode last 4-char into 32-bit serialized class ID (24b name + 5b version + 3b flags) */
uint32_t encName4chars = 0;
for (int j = 0; j < KM_FULLNAME_LEN; j++) {
char *p = strchr(keyMetaCharSet, fullname[j]);
const char *p = strchr(keyMetaCharSet, fullname[j]);
if (!p) return 0; /* Invalid character in name */
unsigned long pos = p - keyMetaCharSet;
encName9Chars = (encName9Chars << KM_ENC_CHAR_BITS) | pos;

View file

@ -7209,7 +7209,7 @@ uint64_t moduleTypeEncodeId(const char *name, int encver) {
uint64_t id = 0;
for (int j = 0; j < 9; j++) {
char *p = strchr(cset,name[j]);
const char *p = strchr(cset,name[j]);
if (!p) return 0;
unsigned long pos = p-cset;
id = (id << 6) | pos;

View file

@ -682,7 +682,7 @@ void afterErrorReply(client *c, const char *s, size_t len, int flags) {
if (s[0] != '-') {
incrementErrorCount("ERR", 3);
} else {
char *spaceloc = memchr(s, ' ', len < 32 ? len : 32);
const char *spaceloc = memchr(s, ' ', len < 32 ? len : 32);
if (spaceloc) {
const size_t errEndPos = (size_t)(spaceloc - s);
incrementErrorCount(s+1, errEndPos-1);

View file

@ -41,7 +41,7 @@
static int parseBulk(ReplyParser *parser, void *p_ctx) {
const char *proto = parser->curr_location;
char *p = strchr(proto+1,'\r');
const char *p = strchr(proto+1,'\r');
long long bulklen;
parser->curr_location = p + 2; /* for \r\n */
@ -60,7 +60,7 @@ static int parseBulk(ReplyParser *parser, void *p_ctx) {
static int parseSimpleString(ReplyParser *parser, void *p_ctx) {
const char *proto = parser->curr_location;
char *p = strchr(proto+1,'\r');
const char *p = strchr(proto+1,'\r');
parser->curr_location = p + 2; /* for \r\n */
parser->callbacks.simple_str_callback(p_ctx, proto+1, p-proto-1, proto, parser->curr_location - proto);
return C_OK;
@ -68,7 +68,7 @@ static int parseSimpleString(ReplyParser *parser, void *p_ctx) {
static int parseError(ReplyParser *parser, void *p_ctx) {
const char *proto = parser->curr_location;
char *p = strchr(proto+1,'\r');
const char *p = strchr(proto+1,'\r');
parser->curr_location = p + 2; // for \r\n
parser->callbacks.error_callback(p_ctx, proto+1, p-proto-1, proto, parser->curr_location - proto);
return C_OK;
@ -76,7 +76,7 @@ static int parseError(ReplyParser *parser, void *p_ctx) {
static int parseLong(ReplyParser *parser, void *p_ctx) {
const char *proto = parser->curr_location;
char *p = strchr(proto+1,'\r');
const char *p = strchr(proto+1,'\r');
parser->curr_location = p + 2; /* for \r\n */
long long val;
string2ll(proto+1,p-proto-1,&val);
@ -86,7 +86,7 @@ static int parseLong(ReplyParser *parser, void *p_ctx) {
static int parseAttributes(ReplyParser *parser, void *p_ctx) {
const char *proto = parser->curr_location;
char *p = strchr(proto+1,'\r');
const char *p = strchr(proto+1,'\r');
long long len;
string2ll(proto+1,p-proto-1,&len);
p += 2;
@ -97,7 +97,7 @@ static int parseAttributes(ReplyParser *parser, void *p_ctx) {
static int parseVerbatimString(ReplyParser *parser, void *p_ctx) {
const char *proto = parser->curr_location;
char *p = strchr(proto+1,'\r');
const char *p = strchr(proto+1,'\r');
long long bulklen;
parser->curr_location = p + 2; /* for \r\n */
string2ll(proto+1,p-proto-1,&bulklen);
@ -110,7 +110,7 @@ static int parseVerbatimString(ReplyParser *parser, void *p_ctx) {
static int parseBigNumber(ReplyParser *parser, void *p_ctx) {
const char *proto = parser->curr_location;
char *p = strchr(proto+1,'\r');
const char *p = strchr(proto+1,'\r');
parser->curr_location = p + 2; /* for \r\n */
parser->callbacks.big_number_callback(p_ctx, proto+1, p-proto-1, proto, parser->curr_location - proto);
return C_OK;
@ -118,7 +118,7 @@ static int parseBigNumber(ReplyParser *parser, void *p_ctx) {
static int parseNull(ReplyParser *parser, void *p_ctx) {
const char *proto = parser->curr_location;
char *p = strchr(proto+1,'\r');
const char *p = strchr(proto+1,'\r');
parser->curr_location = p + 2; /* for \r\n */
parser->callbacks.null_callback(p_ctx, proto, parser->curr_location - proto);
return C_OK;
@ -126,7 +126,7 @@ static int parseNull(ReplyParser *parser, void *p_ctx) {
static int parseDouble(ReplyParser *parser, void *p_ctx) {
const char *proto = parser->curr_location;
char *p = strchr(proto+1,'\r');
const char *p = strchr(proto+1,'\r');
parser->curr_location = p + 2; /* for \r\n */
size_t len = p-proto-1;
double d;
@ -141,7 +141,7 @@ static int parseDouble(ReplyParser *parser, void *p_ctx) {
static int parseBool(ReplyParser *parser, void *p_ctx) {
const char *proto = parser->curr_location;
char *p = strchr(proto+1,'\r');
const char *p = strchr(proto+1,'\r');
parser->curr_location = p + 2; /* for \r\n */
parser->callbacks.bool_callback(p_ctx, proto[1] == 't', proto, parser->curr_location - proto);
return C_OK;
@ -149,7 +149,7 @@ static int parseBool(ReplyParser *parser, void *p_ctx) {
static int parseArray(ReplyParser *parser, void *p_ctx) {
const char *proto = parser->curr_location;
char *p = strchr(proto+1,'\r');
const char *p = strchr(proto+1,'\r');
long long len;
string2ll(proto+1,p-proto-1,&len);
p += 2;
@ -164,7 +164,7 @@ static int parseArray(ReplyParser *parser, void *p_ctx) {
static int parseSet(ReplyParser *parser, void *p_ctx) {
const char *proto = parser->curr_location;
char *p = strchr(proto+1,'\r');
const char *p = strchr(proto+1,'\r');
long long len;
string2ll(proto+1,p-proto-1,&len);
p += 2;
@ -175,7 +175,7 @@ static int parseSet(ReplyParser *parser, void *p_ctx) {
static int parseMap(ReplyParser *parser, void *p_ctx) {
const char *proto = parser->curr_location;
char *p = strchr(proto+1,'\r');
const char *p = strchr(proto+1,'\r');
long long len;
string2ll(proto+1,p-proto-1,&len);
p += 2;