From fc8eb8ce8cf65dc3a0651d555ae14f5339efffef Mon Sep 17 00:00:00 2001 From: Myria Date: Sat, 26 Dec 2015 11:38:37 -0800 Subject: [PATCH] Fix a bunch of Visual Studio compilation warnings, mostly related to truncating integers. --- ctrtool/cia.c | 12 +++++----- ctrtool/ctr.c | 2 +- ctrtool/cwav.c | 10 ++++---- ctrtool/filepath.c | 2 +- ctrtool/ivfc.c | 8 +++---- ctrtool/main.c | 6 ++--- ctrtool/ncch.c | 8 +++---- ctrtool/ncsd.c | 2 +- ctrtool/romfs.c | 6 ++--- ctrtool/utils.c | 60 +++++++++++++++++++++++----------------------- 10 files changed, 58 insertions(+), 58 deletions(-) diff --git a/ctrtool/cia.c b/ctrtool/cia.c index 91333bd..c2ba55b 100644 --- a/ctrtool/cia.c +++ b/ctrtool/cia.c @@ -46,7 +46,7 @@ void cia_save(cia_context* ctx, u32 type, u32 flags) filepath* path = 0; ctr_tmd_body *body; ctr_tmd_contentchunk *chunk; - int i; + unsigned int i; char tmpname[255]; switch(type) @@ -151,7 +151,7 @@ void cia_save_blob(cia_context *ctx, char *out_path, u64 offset, u64 size, int d { u32 max = sizeof(buffer); if (max > size) - max = size; + max = (u32) size; if (max != fread(buffer, 1, max, ctx->file)) { @@ -195,9 +195,9 @@ void cia_process(cia_context* ctx, u32 actions) ctx->sizemeta = getle32(ctx->header.metasize); ctx->offsetcerts = align(ctx->sizeheader, 64); - ctx->offsettik = align(ctx->offsetcerts + ctx->sizecert, 64); - ctx->offsettmd = align(ctx->offsettik + ctx->sizetik, 64); - ctx->offsetcontent = align(ctx->offsettmd + ctx->sizetmd, 64); + ctx->offsettik = align((u32) (ctx->offsetcerts + ctx->sizecert), 64); + ctx->offsettmd = align((u32) (ctx->offsettik + ctx->sizetik), 64); + ctx->offsetcontent = align((u32) (ctx->offsettmd + ctx->sizetmd), 64); ctx->offsetmeta = align64(ctx->offsetcontent + ctx->sizecontent, 64); if (actions & InfoFlag) @@ -253,7 +253,7 @@ void cia_verify_contents(cia_context *ctx, u32 actions) ctr_tmd_contentchunk *chunk; u8 *verify_buf; u32 content_size=0; - int i; + unsigned i; // verify TMD content hashes, requires decryption .. body = tmd_get_body(&ctx->tmd); diff --git a/ctrtool/ctr.c b/ctrtool/ctr.c index 6948bf8..e5198f7 100644 --- a/ctrtool/ctr.c +++ b/ctrtool/ctr.c @@ -244,7 +244,7 @@ int ctr_rsa_verify_hash(const u8 signature[0x100], const u8 hash[0x20], rsakey20 { ctr_rsa_context ctx; u32 result; - u8 output[0x100]; +// u8 output[0x100]; if (key->keytype == RSAKEY_INVALID) return Fail; diff --git a/ctrtool/cwav.c b/ctrtool/cwav.c index 4c1242d..cf9f59b 100644 --- a/ctrtool/cwav.c +++ b/ctrtool/cwav.c @@ -429,7 +429,7 @@ int cwav_dspadpcm_setup(cwav_dspadpcmstate* state, cwav_context* ctx, int isloop } state->channelstate[i].samplebuffer = state->samplebuffer + SAMPLECOUNT * i; - state->channelstate[i].sampleoffset = ctx->offset + getle32(adpcmchannel->info.sampleref.offset) + getle32(ctx->header.datablockref.offset) + 8 + startoffset; + state->channelstate[i].sampleoffset = (u32) (ctx->offset + getle32(adpcmchannel->info.sampleref.offset) + getle32(ctx->header.datablockref.offset) + 8 + startoffset); if (isloop) { state->channelstate[i].yn1 = getle16(adpcminfo->loopyn1); @@ -627,7 +627,7 @@ int cwav_imaadpcm_setup(cwav_imaadpcmstate* state, cwav_context* ctx, int isloop } state->channelstate[i].samplebuffer = state->samplebuffer + SAMPLECOUNT * i; - state->channelstate[i].sampleoffset = ctx->offset + getle32(adpcmchannel->info.sampleref.offset) + getle32(ctx->header.datablockref.offset) + 8 + startoffset; + state->channelstate[i].sampleoffset = (u32) (ctx->offset + getle32(adpcmchannel->info.sampleref.offset) + getle32(ctx->header.datablockref.offset) + 8 + startoffset); if (isloop) { state->channelstate[i].data = getle16(adpcminfo->loopdata); @@ -826,7 +826,7 @@ int cwav_pcm_setup(cwav_pcmstate* state, cwav_context* ctx, int isloop) cwav_channel* pcmchannel = &ctx->channel[i]; state->channelstate[i].samplebuffer = state->samplebuffer + SAMPLECOUNT * i; - state->channelstate[i].sampleoffset = ctx->offset + getle32(pcmchannel->info.sampleref.offset) + getle32(ctx->header.datablockref.offset) + 8 + startoffset; + state->channelstate[i].sampleoffset = (u32) (ctx->offset + getle32(pcmchannel->info.sampleref.offset) + getle32(ctx->header.datablockref.offset) + 8 + startoffset); stream_in_allocate(&state->channelstate[i].instreamctx, BUFFERSIZE, ctx->file); stream_in_seek(&state->channelstate[i].instreamctx, state->channelstate[i].sampleoffset); } @@ -932,7 +932,7 @@ void cwav_print(cwav_context* ctx) cwav_header* header = &ctx->header; cwav_infoheader* infoheader = &ctx->infoheader; u32 i; - u32 infoheaderoffset = ctx->offset + getle32(ctx->header.infoblockref.offset); + u32 infoheaderoffset = (u32) (ctx->offset + getle32(ctx->header.infoblockref.offset)); u32 channelcount = getle32(infoheader->channelcount); fprintf(stdout, "Header: %c%c%c%c\n", header->magic[0], header->magic[1], header->magic[2], header->magic[3]); @@ -962,7 +962,7 @@ void cwav_print(cwav_context* ctx) { u32 channeloffset = infoheaderoffset + 0x1C + getle32(ctx->channel[i].inforef.offset); u32 codecoffset = channeloffset + getle32(ctx->channel[i].info.codecref.offset); - u32 sampleoffset = ctx->offset + getle32(ctx->channel[i].info.sampleref.offset) + getle32(ctx->header.datablockref.offset) + 8; + u32 sampleoffset = (u32) (ctx->offset + getle32(ctx->channel[i].info.sampleref.offset) + getle32(ctx->header.datablockref.offset) + 8); fprintf(stdout, "Channel %d:\n", i); fprintf(stdout, " > Channel ref idtype: 0x%04X\n", getle16(ctx->channel[i].inforef.idtype)); diff --git a/ctrtool/filepath.c b/ctrtool/filepath.c index 94321e2..366bb65 100644 --- a/ctrtool/filepath.c +++ b/ctrtool/filepath.c @@ -47,7 +47,7 @@ void filepath_append_utf16(filepath* fpath, const u8* name) if (code > 0x7F) code = '#'; - fpath->pathname[size++] = code; + fpath->pathname[size++] = (char) code; } fpath->pathname[size] = 0; diff --git a/ctrtool/ivfc.c b/ctrtool/ivfc.c index fb7a5f0..041afda 100644 --- a/ctrtool/ivfc.c +++ b/ctrtool/ivfc.c @@ -51,7 +51,7 @@ void ivfc_fseek(ivfc_context* ctx, u64 offset) u64 data_pos = offset - ctx->offset; fseeko64(ctx->file, offset, SEEK_SET); ctr_init_counter(&ctx->aes, ctx->key, ctx->counter); - ctr_add_counter(&ctx->aes, data_pos / 0x10); + ctr_add_counter(&ctx->aes, (u32) (data_pos / 0x10)); } size_t ivfc_fread(ivfc_context* ctx, void* buffer, size_t size, size_t count) @@ -128,7 +128,7 @@ void ivfc_verify(ivfc_context* ctx, u32 flags) { ivfc_level* level = ctx->level + i; - blockcount = level->datasize / level->hashblocksize; + blockcount = (u32) (level->datasize / level->hashblocksize); if (level->datasize % level->hashblocksize != 0) { fprintf(stderr, "Error, IVFC block size mismatch\n"); @@ -160,7 +160,7 @@ void ivfc_read(ivfc_context* ctx, u64 offset, u64 size, u8* buffer) } ivfc_fseek(ctx, ctx->offset + offset); - if (size != ivfc_fread(ctx, buffer, 1, size)) + if (size != ivfc_fread(ctx, buffer, 1, (size_t) size)) { fprintf(stderr, "Error, IVFC could not read file\n"); return; @@ -177,7 +177,7 @@ void ivfc_hash(ivfc_context* ctx, u64 offset, u64 size, u8* hash) ivfc_read(ctx, offset, size, ctx->buffer); - ctr_sha_256(ctx->buffer, size, hash); + ctr_sha_256(ctx->buffer, (u32) size, hash); } void ivfc_print(ivfc_context* ctx) diff --git a/ctrtool/main.c b/ctrtool/main.c index 4a7199b..7997f17 100644 --- a/ctrtool/main.c +++ b/ctrtool/main.c @@ -344,7 +344,7 @@ int main(int argc, char* argv[]) firm_init(&firmctx); firm_set_file(&firmctx, ctx.infile); - firm_set_size(&firmctx, ctx.infilesize); + firm_set_size(&firmctx, (u32) ctx.infilesize); firm_set_usersettings(&firmctx, &ctx.usersettings); firm_process(&firmctx, ctx.actions); @@ -399,7 +399,7 @@ int main(int argc, char* argv[]) tmd_init(&tmdctx); tmd_set_file(&tmdctx, ctx.infile); - tmd_set_size(&tmdctx, ctx.infilesize); + tmd_set_size(&tmdctx, (u32) ctx.infilesize); tmd_set_usersettings(&tmdctx, &ctx.usersettings); tmd_process(&tmdctx, ctx.actions); @@ -412,7 +412,7 @@ int main(int argc, char* argv[]) lzss_init(&lzssctx); lzss_set_file(&lzssctx, ctx.infile); - lzss_set_size(&lzssctx, ctx.infilesize); + lzss_set_size(&lzssctx, (u32) ctx.infilesize); lzss_set_usersettings(&lzssctx, &ctx.usersettings); lzss_process(&lzssctx, ctx.actions); diff --git a/ctrtool/ncch.c b/ctrtool/ncch.c index 7c06b23..8d2a9ff 100644 --- a/ctrtool/ncch.c +++ b/ctrtool/ncch.c @@ -48,7 +48,7 @@ void ncch_set_file(ncch_context* ctx, FILE* file) void ncch_get_counter(ncch_context* ctx, u8 counter[16], u8 type) { u32 version = getle16(ctx->header.version); - u32 mediaunitsize = ncch_get_mediaunit_size(ctx); + u32 mediaunitsize = (u32) ncch_get_mediaunit_size(ctx); u8* partitionid = ctx->header.partitionid; u32 i; u64 x = 0; @@ -73,7 +73,7 @@ void ncch_get_counter(ncch_context* ctx, u8 counter[16], u8 type) for(i=0; i<8; i++) counter[i] = partitionid[i]; for(i=0; i<4; i++) - counter[12+i] = x>>((3-i)*8); + counter[12+i] = (u8) (x>>((3-i)*8)); } } @@ -148,7 +148,7 @@ int ncch_extract_buffer(ncch_context* ctx, u8* buffer, u32 buffersize, u32* outs u32 read_len = buffersize; if (read_len > ctx->extractsize) - read_len = ctx->extractsize; + read_len = (u32) ctx->extractsize; *outsize = read_len; @@ -234,7 +234,7 @@ clean: void ncch_verify(ncch_context* ctx, u32 flags) { - u32 mediaunitsize = ncch_get_mediaunit_size(ctx); + u32 mediaunitsize = (u32) ncch_get_mediaunit_size(ctx); u32 exefshashregionsize = getle32(ctx->header.exefshashregionsize) * mediaunitsize; u32 romfshashregionsize = getle32(ctx->header.romfshashregionsize) * mediaunitsize; u32 exheaderhashregionsize = getle32(ctx->header.extendedheadersize); diff --git a/ctrtool/ncsd.c b/ctrtool/ncsd.c index 384216a..4a7d928 100644 --- a/ctrtool/ncsd.c +++ b/ctrtool/ncsd.c @@ -120,7 +120,7 @@ void ncsd_print(ncsd_context* ctx) char magic[5]; ctr_ncsdheader* header = &ctx->header; unsigned int i; - unsigned int mediaunitsize = ncsd_get_mediaunit_size(ctx); + unsigned int mediaunitsize = (unsigned int) ncsd_get_mediaunit_size(ctx); memcpy(magic, header->magic, 4); diff --git a/ctrtool/romfs.c b/ctrtool/romfs.c index 5889bdc..f8c9ffb 100644 --- a/ctrtool/romfs.c +++ b/ctrtool/romfs.c @@ -50,7 +50,7 @@ void romfs_fseek(romfs_context* ctx, u64 offset) u64 data_pos = offset - ctx->offset; fseeko64(ctx->file, offset, SEEK_SET); ctr_init_counter(&ctx->aes, ctx->key, ctx->counter); - ctr_add_counter(&ctx->aes, data_pos / 0x10); + ctr_add_counter(&ctx->aes, (u32) (data_pos / 0x10)); } size_t romfs_fread(romfs_context* ctx, void* buffer, size_t size, size_t count) @@ -91,7 +91,7 @@ void romfs_process(romfs_context* ctx, u32 actions) return; } - ctx->infoblockoffset = ctx->offset + 0x1000; + ctx->infoblockoffset = (u32) (ctx->offset + 0x1000); romfs_fseek(ctx, ctx->infoblockoffset); romfs_fread(ctx, &ctx->infoheader, 1, sizeof(romfs_infoheader)); @@ -363,7 +363,7 @@ void romfs_extract_datafile(romfs_context* ctx, u64 offset, u64 size, const osch { max = sizeof(buffer); if (max > size) - max = size; + max = (u32) size; if (max != romfs_fread(ctx, buffer, 1, max)) { diff --git a/ctrtool/utils.c b/ctrtool/utils.c index 1f21f07..fe12a62 100644 --- a/ctrtool/utils.c +++ b/ctrtool/utils.c @@ -73,59 +73,59 @@ u32 getbe16(const u8* p) void putle16(u8* p, u16 n) { - p[0] = n; - p[1] = n>>8; + p[0] = (u8) n; + p[1] = (u8) (n>>8); } void putle32(u8* p, u32 n) { - p[0] = n; - p[1] = n>>8; - p[2] = n>>16; - p[3] = n>>24; + p[0] = (u8) n; + p[1] = (u8) (n>>8); + p[2] = (u8) (n>>16); + p[3] = (u8) (n>>24); } void putle64(u8* p, u64 n) { - p[0] = n; - p[1] = n >> 8; - p[2] = n >> 16; - p[3] = n >> 24; - p[4] = n >> 32; - p[5] = n >> 40; - p[6] = n >> 48; - p[7] = n >> 56; + p[0] = (u8) n; + p[1] = (u8) (n >> 8); + p[2] = (u8) (n >> 16); + p[3] = (u8) (n >> 24); + p[4] = (u8) (n >> 32); + p[5] = (u8) (n >> 40); + p[6] = (u8) (n >> 48); + p[7] = (u8) (n >> 56); } void putbe16(u8* p, u16 n) { - p[1] = n; - p[0] = n >> 8; + p[1] = (u8) n; + p[0] = (u8) (n >> 8); } void putbe32(u8* p, u32 n) { - p[3] = n; - p[2] = n >> 8; - p[1] = n >> 16; - p[0] = n >> 24; + p[3] = (u8) n; + p[2] = (u8) (n >> 8); + p[1] = (u8) (n >> 16); + p[0] = (u8) (n >> 24); } void putbe64(u8* p, u64 n) { - p[7] = n; - p[6] = n >> 8; - p[5] = n >> 16; - p[4] = n >> 24; - p[3] = n >> 32; - p[2] = n >> 40; - p[1] = n >> 48; - p[0] = n >> 56; + p[7] = (u8) n; + p[6] = (u8) (n >> 8); + p[5] = (u8) (n >> 16); + p[4] = (u8) (n >> 24); + p[3] = (u8) (n >> 32); + p[2] = (u8) (n >> 40); + p[1] = (u8) (n >> 48); + p[0] = (u8) (n >> 56); } void readkeyfile(u8* key, const char* keyfname) { - u32 keysize = _fsize(keyfname); + u64 keysize = _fsize(keyfname); FILE* f = fopen(keyfname, "rb"); if (0 == f) @@ -136,7 +136,7 @@ void readkeyfile(u8* key, const char* keyfname) if (keysize != 16) { - fprintf(stdout, "Error key size mismatch, got %d, expected %d\n", keysize, 16); + fprintf(stdout, "Error key size mismatch, got %"PRId64", expected %d\n", keysize, 16); goto clean; }