diff --git a/src/meta/xnb.c b/src/meta/xnb.c index 98aac098..c7f74c6e 100644 --- a/src/meta/xnb.c +++ b/src/meta/xnb.c @@ -41,7 +41,7 @@ VGMSTREAM * init_vgmstream_xnb(STREAMFILE *streamFile) { { char reader_name[255+1]; off_t current_offset = 0x0a; - int reader_string_len; + size_t reader_string_len; uint32_t fmt_chunk_size; const char * type_sound = "Microsoft.Xna.Framework.Content.SoundEffectReader"; /* partial "fmt" chunk or XMA */ //const char * type_song = "Microsoft.Xna.Framework.Content.SongReader"; /* just references a companion .wma */ diff --git a/src/meta/xwb.c b/src/meta/xwb.c index fdb2f196..550070c2 100644 --- a/src/meta/xwb.c +++ b/src/meta/xwb.c @@ -534,13 +534,13 @@ fail: /* try to get the stream name in the .xwb, though they are very rarely included */ static int get_xwb_name(char * buf, size_t maxsize, int target_subsong, xwb_header * xwb, STREAMFILE *streamFile) { - int read; + size_t read; if (!xwb->names_offset || !xwb->names_size || xwb->names_entry_size > maxsize) goto fail; read = read_string(buf,xwb->names_entry_size, xwb->names_offset + xwb->names_entry_size*(target_subsong-1),streamFile); - if (read <= 0) goto fail; + if (read == 0) goto fail; return 1; diff --git a/src/streamfile.c b/src/streamfile.c index 1dd50056..a02c2ab8 100644 --- a/src/streamfile.c +++ b/src/streamfile.c @@ -740,17 +740,17 @@ size_t get_streamfile_text_line(int dst_length, char * dst, off_t offset, STREAM } -/* reads a c-string, up to maxsize or NULL, returning size. buf is optional. */ -int read_string(char * buf, size_t maxsize, off_t offset, STREAMFILE *streamFile) { - int i; +/* reads a c-string (ANSI only), up to maxsize or NULL, returning size. buf is optional (works as get_string_size). */ +size_t read_string(char * buf, size_t maxsize, off_t offset, STREAMFILE *streamFile) { + size_t pos; - for (i=0; i < maxsize; i++) { - char c = read_8bit(offset + i, streamFile); - if (buf) buf[i] = c; + for (pos = 0; pos < maxsize; pos++) { + char c = read_8bit(offset + pos, streamFile); + if (buf) buf[pos] = c; if (c == '\0') - return i; - if (i+1 == maxsize) { /* null at maxsize and don't validate (expected to be garbage) */ - if (buf) buf[i] = '\0'; + return pos; + if (pos+1 == maxsize) { /* null at maxsize and don't validate (expected to be garbage) */ + if (buf) buf[pos] = '\0'; return maxsize; } if (c < 0x20 || c > 0xA5) diff --git a/src/streamfile.h b/src/streamfile.h index 520e0d02..2f920f85 100644 --- a/src/streamfile.h +++ b/src/streamfile.h @@ -167,7 +167,7 @@ size_t get_streamfile_text_line(int dst_length, char * dst, off_t offset, STREAM STREAMFILE * open_stream_ext(STREAMFILE *streamFile, const char * ext); STREAMFILE * open_stream_name(STREAMFILE *streamFile, const char * ext); -int read_string(char * buf, size_t bufsize, off_t offset, STREAMFILE *streamFile); +size_t read_string(char * buf, size_t bufsize, off_t offset, STREAMFILE *streamFile); size_t read_key_file(uint8_t * buf, size_t bufsize, STREAMFILE *streamFile);