Return size_t in read_string for consistency

This commit is contained in:
bnnm 2018-03-29 20:42:52 +02:00
parent 49e62d2bcc
commit 69fb29fc7a
4 changed files with 13 additions and 13 deletions

View File

@ -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 */

View File

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

View File

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

View File

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