BUG 2409: avoid using integer values >= 2^31 in the CR.

This commit is contained in:
Enno Rehling 2018-01-08 19:45:49 +01:00
parent a48d177472
commit 5587e209a2
2 changed files with 8 additions and 7 deletions

View File

@ -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);
}
}

View File

@ -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;