From 5587e209a2e4dd86e534d2590c182fc802050d64 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Mon, 8 Jan 2018 19:45:49 +0100 Subject: [PATCH] BUG 2409: avoid using integer values >= 2^31 in the CR. --- src/creport.c | 14 +++++++------- src/util/message.c | 1 + 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/creport.c b/src/creport.c index e5732036a..4e8fe95b6 100644 --- a/src/creport.c +++ b/src/creport.c @@ -513,9 +513,9 @@ static void report_crtypes(FILE * F, const struct locale *lang) const struct nrmessage_type *nrt = nrt_find(lang, kmt->mtype); if (nrt) { char buffer[DISPLAYSIZE]; - unsigned int hash = kmt->mtype->key; + int hash = (int)kmt->mtype->key; assert(hash > 0); - fprintf(F, "MESSAGETYPE %u\n", hash); + fprintf(F, "MESSAGETYPE %d\n", hash); fputc('\"', F); fputs(str_escape(nrt_string(nrt), buffer, sizeof(buffer)), F); fputs("\";text\n", F); @@ -530,11 +530,11 @@ static void report_crtypes(FILE * F, const struct locale *lang) } } -static unsigned int messagehash(const struct message *msg) +static int message_id(const struct message *msg) { variant var; var.v = (void *)msg; - return (unsigned int)var.i; + return var.i & 0x7FFFFFFF; } /** writes a quoted string to the file @@ -580,7 +580,7 @@ static void render_messages(FILE * F, faction * f, message_list * msgs) char nrbuffer[1024 * 32]; nrbuffer[0] = '\0'; if (nr_render(m->msg, f->locale, nrbuffer, sizeof(nrbuffer), f) > 0) { - fprintf(F, "MESSAGE %u\n", messagehash(m->msg)); + fprintf(F, "MESSAGE %d\n", message_id(m->msg)); fprintf(F, "%u;type\n", hash); fwritestr(F, nrbuffer); fputs(";rendered\n", F); @@ -591,7 +591,7 @@ static void render_messages(FILE * F, faction * f, message_list * msgs) if (cr_render(m->msg, crbuffer, (const void *)f) == 0) { if (crbuffer[0]) { if (!printed) { - fprintf(F, "MESSAGE %u\n", messagehash(m->msg)); + fprintf(F, "MESSAGE %d\n", message_id(m->msg)); } fputs(crbuffer, F); } @@ -814,7 +814,7 @@ void cr_output_unit(stream *out, const faction * f, } mage = get_familiar_mage(u); if (mage) { - stream_printf(out, "%u;familiarmage\n", mage->no); + stream_printf(out, "%d;familiarmage\n", mage->no); } } diff --git a/src/util/message.c b/src/util/message.c index 737519585..a080ff7a6 100644 --- a/src/util/message.c +++ b/src/util/message.c @@ -213,6 +213,7 @@ static unsigned int mt_id(const message_type * mtype) size_t i = strlen(mtype->name); while (i > 0) { + /* TODO: why not use str_hash? */ key = (mtype->name[--i] + key * 37); } return key % 0x7FFFFFFF;