Skip to content

Commit 9a20f49

Browse files
authored
Resolve Compilation Errors with ARM GCC on Ubuntu 22.04 (#54)
The issues were related to cross-platform compatibility of printf format arguments.
1 parent efff6b5 commit 9a20f49

File tree

4 files changed

+24
-23
lines changed

4 files changed

+24
-23
lines changed

src/ext/handlersToJson.c

100644100755
+13-13
Original file line numberDiff line numberDiff line change
@@ -173,9 +173,9 @@ static RdbRes toJsonSlotInfo(RdbParser *p, void *userData, RdbSlotInfo *info) {
173173

174174
/* output json part */
175175
fprintf(ctx->outfile, " \"%sslotinfo__\": {\n", jsonMetaPrefix);
176-
fprintf(ctx->outfile, " \"slotId\": %lu,\n", info->slot_id);
177-
fprintf(ctx->outfile, " \"slotSize\": %lu,\n", info->slot_size);
178-
fprintf(ctx->outfile, " \"slotSExpiresSize\": %lu\n", info->expires_slot_size);
176+
fprintf(ctx->outfile, " \"slotId\": %" PRIu64 ",\n", info->slot_id);
177+
fprintf(ctx->outfile, " \"slotSize\": %" PRIu64 ",\n", info->slot_size);
178+
fprintf(ctx->outfile, " \"slotSExpiresSize\": %" PRIu64 "\n", info->expires_slot_size);
179179
fprintf(ctx->outfile, " },\n");
180180
return RDB_OK;
181181
}
@@ -353,7 +353,7 @@ static RdbRes toJsonModule(RdbParser *p, void *userData, RdbBulk moduleName, siz
353353
}
354354

355355
/* output json part */
356-
fprintf(ctx->outfile, "\"<Content of Module '%s'. Occupies a serialized size of %ld bytes>\"",
356+
fprintf(ctx->outfile, "\"<Content of Module '%s'. Occupies a serialized size of %zu bytes>\"",
357357
moduleName,
358358
serializedSize);
359359

@@ -532,7 +532,7 @@ static RdbRes toJsonStreamItem(RdbParser *p, void *userData, RdbStreamID *id, Rd
532532
fprintf(ctx->outfile, "{\n \"entries\":[");
533533

534534
/* output another stream entry */
535-
fprintf(ctx->outfile, "%c\n { \"id\":\"%lu-%lu\", ",
535+
fprintf(ctx->outfile, "%c\n { \"id\":\"%" PRIu64 "-%" PRIu64 "\", ",
536536
(ctx->state == R2J_IN_STREAM_ENTRIES) ? ',' : ' ',
537537
id->ms, id->seq );
538538
fprintf(ctx->outfile, "\"items\":{");
@@ -570,11 +570,11 @@ static RdbRes toJsonStreamMetadata(RdbParser *p, void *userData, RdbStreamMeta *
570570
return (RdbRes) RDBX_ERR_R2J_INVALID_STATE;
571571
}
572572
ctx->state = R2J_IN_STREAM;
573-
fprintf(ctx->outfile, "],\n \"length\": %lu, ", meta->length);
574-
fprintf(ctx->outfile, "\n \"entriesAdded\": %lu, ", meta->entriesAdded);
575-
fprintf(ctx->outfile, "\n \"firstID\": \"%lu-%lu\", ", meta->firstID.ms, meta->firstID.seq);
576-
fprintf(ctx->outfile, "\n \"lastID\": \"%lu-%lu\", ", meta->lastID.ms, meta->lastID.seq);
577-
fprintf(ctx->outfile, "\n \"maxDelEntryID\": \"%lu-%lu\",", meta->maxDelEntryID.ms, meta->maxDelEntryID.seq);
573+
fprintf(ctx->outfile, "],\n \"length\": %" PRIu64 ", ", meta->length);
574+
fprintf(ctx->outfile, "\n \"entriesAdded\": %" PRIu64 ", ", meta->entriesAdded);
575+
fprintf(ctx->outfile, "\n \"firstID\": \"%" PRIu64 "-%" PRIu64 "\", ", meta->firstID.ms, meta->firstID.seq);
576+
fprintf(ctx->outfile, "\n \"lastID\": \"%" PRIu64 "-%" PRIu64 "\", ", meta->lastID.ms, meta->lastID.seq);
577+
fprintf(ctx->outfile, "\n \"maxDelEntryID\": \"%" PRIu64 "-%" PRIu64 "\",", meta->maxDelEntryID.ms, meta->maxDelEntryID.seq);
578578
return RDB_OK;
579579
}
580580

@@ -596,7 +596,7 @@ static RdbRes toJsonStreamNewCGroup(RdbParser *p, void *userData, RdbBulk grpNam
596596
"toJsonStreamNewCGroup(): Invalid state value: %d", ctx->state);
597597
return (RdbRes) RDBX_ERR_R2J_INVALID_STATE;
598598
}
599-
fprintf(ctx->outfile, "%s {\"name\": \"%s\", \"lastid\": \"%lu-%lu\", \"entriesRead\": %lu",
599+
fprintf(ctx->outfile, "%s {\"name\": \"%s\", \"lastid\": \"%" PRIu64 "-%" PRIu64 "\", \"entriesRead\": %" PRIu64,
600600
prefix, grpName, meta->lastId.ms, meta->lastId.seq, meta->entriesRead);
601601

602602
ctx->state = R2J_IN_STREAM_CG;
@@ -616,7 +616,7 @@ static RdbRes toJsonStreamCGroupPendingEntry(RdbParser *p, void *userData, RdbSt
616616
"toJsonStreamCGroupPendingEntry(): Invalid state value: %d", ctx->state);
617617
return (RdbRes) RDBX_ERR_R2J_INVALID_STATE;
618618
}
619-
fprintf(ctx->outfile, "%s\n { \"sent\": %lu, \"id\":\"%lu-%lu\", \"count\": %lu }",
619+
fprintf(ctx->outfile, "%s\n { \"sent\": %" PRIu64 ", \"id\":\"%" PRIu64 "-%" PRIu64 "\", \"count\": %" PRIu64 " }",
620620
prefix, pe->deliveryTime, pe->id.ms, pe->id.seq, pe->deliveryCount);
621621
return RDB_OK;
622622
}
@@ -659,7 +659,7 @@ static RdbRes toJsonStreamConsumerPendingEntry(RdbParser *p, void *userData, Rdb
659659
}
660660

661661
ctx->state = R2J_IN_STREAM_CG_CONSUMER_PEL;
662-
fprintf(ctx->outfile, "%s\n {\"id\":\"%lu-%lu\"}", prefix, streamId->ms, streamId->seq);
662+
fprintf(ctx->outfile, "%s\n {\"id\":\"%" PRIu64 "-%" PRIu64 "\"}", prefix, streamId->ms, streamId->seq);
663663
return RDB_OK;
664664
}
665665

src/ext/handlersToResp.c

+7-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include <string.h>
22
#include <assert.h>
33
#include <sys/uio.h>
4+
#include <inttypes.h>
45
#include "common.h"
56

67
#include "../../deps/redis/crc64.h"
@@ -641,8 +642,8 @@ static RdbRes toRespStreamMetaData(RdbParser *p, void *userData, RdbStreamMeta *
641642
/* take care to reset it for next stream-item */
642643
ctx->streamCtx.xaddStartEndCounter = 0;
643644

644-
int idLen = snprintf(idStr, sizeof(idStr), "%lu-%lu",meta->lastID.ms,meta->lastID.seq);
645-
int maxDelEntryIdLen = snprintf(maxDelEntryId, sizeof(maxDelEntryId), "%lu-%lu", meta->maxDelEntryID.ms, meta->maxDelEntryID.seq);
645+
int idLen = snprintf(idStr, sizeof(idStr), "%" PRIu64 "-%" PRIu64,meta->lastID.ms,meta->lastID.seq);
646+
int maxDelEntryIdLen = snprintf(maxDelEntryId, sizeof(maxDelEntryId), "%" PRIu64 "-%" PRIu64, meta->maxDelEntryID.ms, meta->maxDelEntryID.seq);
646647

647648
RdbxRespWriterStartCmd startCmd = {"XSETID", ctx->keyCtx.key, 0};
648649

@@ -686,11 +687,11 @@ static RdbRes toRespStreamItem(RdbParser *p, void *userData, RdbStreamID *id, Rd
686687
startCmdRef = &startCmd;
687688

688689
/* writev XADD */
689-
int cmdLen = snprintf(cmd, sizeof(cmd), "*%lu\r\n$4\r\nXADD", 3 + (itemsLeft + 1) * 2);
690+
int cmdLen = snprintf(cmd, sizeof(cmd), "*%" PRIu64 "\r\n$4\r\nXADD", 3 + (itemsLeft + 1) * 2);
690691
IOV_STRING(&iov[iovs++], cmd, cmdLen);
691692
IOV_LENGTH(&iov[iovs++], ctx->keyCtx.keyLen, keyLenStr);
692693
IOV_STRING(&iov[iovs++], ctx->keyCtx.key, ctx->keyCtx.keyLen);
693-
int idLen = snprintf(idStr, sizeof(idStr), "%lu-%lu",id->ms,id->seq);
694+
int idLen = snprintf(idStr, sizeof(idStr), "%" PRIu64 "-%" PRIu64,id->ms,id->seq);
694695
IOV_LENGTH(&iov[iovs++], idLen, idLenStr);
695696
IOV_STRING(&iov[iovs++], idStr, idLen);
696697

@@ -731,7 +732,7 @@ static RdbRes toRespStreamNewCGroup(RdbParser *p, void *userData, RdbBulk grpNam
731732
if(!(ctx->streamCtx.groupPel = raxNew()))
732733
return RDB_ERR_FAIL_ALLOC;
733734

734-
int idLen = snprintf(idStr, sizeof(idStr), "%lu-%lu",meta->lastId.ms,meta->lastId.seq);
735+
int idLen = snprintf(idStr, sizeof(idStr), "%" PRIu64 "-%" PRIu64,meta->lastId.ms,meta->lastId.seq);
735736

736737
RdbxRespWriterStartCmd startCmd = { "XGROUP", ctx->keyCtx.key, 0};
737738

@@ -828,7 +829,7 @@ static RdbRes toRespStreamConsumerPendingEntry(RdbParser *p, void *userData, Rdb
828829
IOV_LENGTH(&iov[iovs++], ctx->streamCtx.consNameLen, cNameLenStr);
829830
IOV_STRING(&iov[iovs++], ctx->streamCtx.consName, ctx->streamCtx.consNameLen);
830831
/* trailer of the command */
831-
int idLen = snprintf(idStr, sizeof(idStr), "%lu-%lu",streamId->ms, streamId->seq);
832+
int idLen = snprintf(idStr, sizeof(idStr), "%" PRIu64 "-%" PRIu64,streamId->ms, streamId->seq);
832833
int sentTimeLen = ll2string(sentTime, sizeof(sentTime), pe->deliveryTime);
833834
int sentCountLen = ll2string(sentCount, sizeof(sentCount), pe->deliveryCount);
834835
int cmdTrailerLen = snprintf(cmdTrailer, sizeof(cmdTrailer),

src/lib/parser.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -2178,7 +2178,7 @@ RdbStatus elementModule(RdbParser *p) {
21782178
IF_NOT_OK_RETURN(rdbLoadLen(p, NULL, &when, NULL, NULL));
21792179
if (unlikely(when_opcode != RDB_MODULE_OPCODE_UINT)) {
21802180
RDB_reportError(p, RDB_ERR_MODULE_INVALID_WHEN_OPCODE,
2181-
"elementModule() : Invalid when opcode: %ld.", when_opcode);
2181+
"elementModule() : Invalid when opcode: %" PRIu64 ".", when_opcode);
21822182
return RDB_STATUS_ERROR;
21832183
}
21842184
}

src/lib/parserRaw.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -729,7 +729,7 @@ RdbStatus elementRawModule(RdbParser *p) {
729729
IF_NOT_OK_RETURN(rdbLoadLen(p, NULL, &ma->when, NULL, NULL));
730730
if (unlikely(ma->when_opcode != RDB_MODULE_OPCODE_UINT)) {
731731
RDB_reportError(p, RDB_ERR_MODULE_INVALID_WHEN_OPCODE,
732-
"elementRawModule() : Invalid when opcode: %ld.", ma->when_opcode);
732+
"elementRawModule() : Invalid when opcode: %" PRIu64 ".", ma->when_opcode);
733733
return RDB_STATUS_ERROR;
734734
}
735735
/*** ENTER SAFE STATE ***/
@@ -1214,7 +1214,7 @@ static RdbStatus aggMakeRoom(RdbParser *p, size_t numBytesRq) {
12141214
size_t freeRoomLeft = currBuff->len - currBuff->written;
12151215

12161216
if (unlikely(p->maxRawSize < ctx->totalSize + numBytesRq)) {
1217-
RDB_reportError(p, RDB_ERR_MAX_RAW_LEN_EXCEEDED_FOR_KEY, "Maximum raw length exceeded for key (len=%lu)",
1217+
RDB_reportError(p, RDB_ERR_MAX_RAW_LEN_EXCEEDED_FOR_KEY, "Maximum raw length exceeded for key (len=%zu)",
12181218
ctx->totalSize + numBytesRq);
12191219
return RDB_STATUS_ERROR;
12201220
}
@@ -1287,7 +1287,7 @@ void printAggAraryDbg(RdbParser *p) {
12871287
RawContext *ctx = &p->rawCtx;
12881288
for (int i = 0; i <= ctx->curBulkIndex ; ++i) {
12891289
BulkInfo *b = ctx->bulkArray+i;
1290-
printf("bulkArray[%d]: bulkType=%d ref=%p len=%lu written=%lu next=%p\n",
1290+
printf("bulkArray[%d]: bulkType=%d ref=%p len=%zu written=%zu next=%p\n",
12911291
i, b->bulkType, (void *)b->ref, b->len, b->written, (void *)b->next);
12921292
}
12931293
}

0 commit comments

Comments
 (0)