Skip to content

Commit

Permalink
Fixing RDB_reportError format mismatch arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
moticless committed Dec 11, 2023
1 parent 5427582 commit 52ea0d5
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 13 deletions.
7 changes: 6 additions & 1 deletion api/librdb-api.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ extern "C" {
#define _LIBRDB_API __attribute__((visibility("default")))
#endif

#ifndef __GNUC__
#define __attribute__(a)
#endif

typedef char *RdbBulk;
typedef char *RdbBulkCopy;

Expand Down Expand Up @@ -472,7 +476,8 @@ _LIBRDB_API void RDB_pauseParser(RdbParser *p);
****************************************************************/
_LIBRDB_API RdbRes RDB_getErrorCode(RdbParser *p);
_LIBRDB_API const char *RDB_getErrorMessage(RdbParser *p);
_LIBRDB_API void RDB_reportError(RdbParser *p, RdbRes e, const char *msg, ...);
_LIBRDB_API void RDB_reportError(RdbParser *p, RdbRes e, const char *msg, ...)
__attribute__((format(printf, 3, 4)));

/****************************************************************
* Memory management
Expand Down
3 changes: 1 addition & 2 deletions src/ext/readerFile.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@ RdbxReaderFile *RDBX_createReaderFile(RdbParser *p, const char *filename) {
FILE *f;

if (filename == NULL) {
RDB_reportError(p, RDB_ERR_FAILED_OPEN_RDB_FILE,
"Filename is not provided", filename);
RDB_reportError(p, RDB_ERR_FAILED_OPEN_RDB_FILE, "Filename is not provided");
return NULL;
}

Expand Down
2 changes: 1 addition & 1 deletion src/ext/respToFileWriter.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ static int respFileWritev(void *context, struct iovec *iov, int count,
/* not optimized code */
for (int i = 0 ; i < count ; ++i) {
if (unlikely(fwrite(iov[i].iov_base, sizeof(char), iov[i].iov_len, ctx->filePtr) != iov[i].iov_len)) {
RDB_reportError(ctx->p, (RdbRes) RDBX_ERR_RESP_WRITE, "Failed to write RESP to file: %s (errno=%d)", errno);
RDB_reportError(ctx->p, (RdbRes) RDBX_ERR_RESP_WRITE, "Failed to write RESP to file: (errno=%d)", errno);
return 1;
}
}
Expand Down
12 changes: 6 additions & 6 deletions src/lib/parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ _LIBRDB_API size_t RDB_bulkLen(RdbParser *p, RdbBulk b) {
}

RDB_reportError(p, RDB_ERR_INVALID_BULK_LENGTH_REQUEST,
"Invalid RDB_bulkLen() request. Couldn't find application-bulk with address: %p", b);
"Invalid RDB_bulkLen() request. Couldn't find application-bulk with address: %p", (void*)b);

return 0;
}
Expand All @@ -363,7 +363,7 @@ _LIBRDB_API int RDB_isRefBulk(RdbParser *p, RdbBulk b) {
}

RDB_reportError(p, RDB_ERR_INVALID_IS_REF_BULK,
"Invalid RDB_isRefBulk() request. Couldn't find application-bulk with address: %p", b);
"Invalid RDB_isRefBulk() request. Couldn't find application-bulk with address: %p", (void*)b);
return 0;
}

Expand All @@ -375,7 +375,7 @@ _LIBRDB_API RdbBulkCopy RDB_bulkClone(RdbParser *p, RdbBulk b) {
}

RDB_reportError(p, RDB_ERR_INVALID_BULK_CLONE_REQUEST,
"Invalid RDB_bulkClone() request. Couldn't find application-bulk with address: %p", b);
"Invalid RDB_bulkClone() request. Couldn't find application-bulk with address: %p", (void*)b);

return NULL;
}
Expand Down Expand Up @@ -1980,7 +1980,7 @@ RdbStatus elementEndOfFile(RdbParser *p) {
if (cksum == 0) {
RDB_log(p, RDB_LOG_WRN, "RDB file was saved with checksum disabled: no check performed.");
} else if (cksum != evaluated) {
RDB_reportError(p, RDB_ERR_CHECKSUM_FAILURE, "Wrong RDB checksum checksum=%lx, evaluated=%lx",
RDB_reportError(p, RDB_ERR_CHECKSUM_FAILURE, "Wrong RDB checksum checksum=%llx, evaluated=%llx",
(unsigned long long) cksum,
(unsigned long long) p->checksum);
return RDB_STATUS_ERROR;
Expand Down Expand Up @@ -2042,7 +2042,7 @@ RdbStatus elementModule(RdbParser *p) {
IF_NOT_OK_RETURN(rdbLoadLen(p, NULL, &when, NULL, NULL));
if (unlikely(when_opcode != RDB_MODULE_OPCODE_UINT)) {
RDB_reportError(p, RDB_ERR_MODULE_INVALID_WHEN_OPCODE,
"elementModule() : Invalid when opcode: %d.", when_opcode);
"elementModule() : Invalid when opcode: %ld.", when_opcode);
return RDB_STATUS_ERROR;
}
}
Expand Down Expand Up @@ -2588,7 +2588,7 @@ RdbStatus rdbLoadString(RdbParser *p, AllocTypeRq type, char *refBuf, BulkInfo *
return rdbLoadLzfString(p, type, refBuf, binfo);
default:
RDB_reportError(p, RDB_ERR_STRING_UNKNOWN_ENCODING_TYPE,
"rdbLoadString(): Unknown RDB string encoding type: %llu",len);
"rdbLoadString(): Unknown RDB string encoding type: %lu",len);
return RDB_STATUS_ERROR;
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/lib/parserRaw.c
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ RdbStatus elementRawString(RdbParser *p) {
break;
default:
RDB_reportError(p, RDB_ERR_STRING_UNKNOWN_ENCODING_TYPE,
"elementRawString(): Unknown RDB string encoding type: %llu", strCtx->len);
"elementRawString(): Unknown RDB string encoding type: %lu", strCtx->len);
return RDB_STATUS_ERROR;
}
}
Expand Down Expand Up @@ -419,7 +419,7 @@ RdbStatus elementRawString(RdbParser *p) {
}

RDB_reportError(p, RDB_ERR_STRING_UNKNOWN_ENCODING_TYPE,
"elementRawString(): Unknown RDB string encoding type: %llu", strCtx->encoding);
"elementRawString(): Unknown RDB string encoding type: %lu", strCtx->encoding);
return RDB_STATUS_ERROR;
}

Expand Down Expand Up @@ -694,7 +694,7 @@ RdbStatus elementRawModule(RdbParser *p) {
IF_NOT_OK_RETURN(rdbLoadLen(p, NULL, &ma->when, NULL, NULL));
if (unlikely(ma->when_opcode != RDB_MODULE_OPCODE_UINT)) {
RDB_reportError(p, RDB_ERR_MODULE_INVALID_WHEN_OPCODE,
"elementRawModule() : Invalid when opcode: %d.", ma->when_opcode);
"elementRawModule() : Invalid when opcode: %ld.", ma->when_opcode);
return RDB_STATUS_ERROR;
}
/*** ENTER SAFE STATE ***/
Expand Down

0 comments on commit 52ea0d5

Please sign in to comment.