diff options
author | William Wilgus <wilgus.william@gmail.com> | 2021-08-07 00:02:34 -0400 |
---|---|---|
committer | William Wilgus <me.theuser@yahoo.com> | 2021-08-07 04:50:14 +0000 |
commit | 57293f1fd9d091145059293d88bb15c8749bb596 (patch) | |
tree | b410b39adccd4a6b46dd54073aa1e600ece09e66 | |
parent | 60933d98c629ee96cb09bbaafe4be7cfa50358ed (diff) | |
download | rockbox-57293f1fd9d091145059293d88bb15c8749bb596.tar.gz rockbox-57293f1fd9d091145059293d88bb15c8749bb596.zip |
metadata/vfx.c cleanup string and character handling
Change-Id: I7550d6db05b0d31a1433d0af9b2233f9dc3f5ee2
-rw-r--r-- | lib/rbcodec/metadata/vtx.c | 36 |
1 files changed, 19 insertions, 17 deletions
diff --git a/lib/rbcodec/metadata/vtx.c b/lib/rbcodec/metadata/vtx.c index eb06528b29..65401be8b8 100644 --- a/lib/rbcodec/metadata/vtx.c +++ b/lib/rbcodec/metadata/vtx.c | |||
@@ -51,40 +51,42 @@ typedef struct { | |||
51 | #define VTX_STRING_MAX 254 | 51 | #define VTX_STRING_MAX 254 |
52 | 52 | ||
53 | static uint Reader_ReadByte(int fd) { | 53 | static uint Reader_ReadByte(int fd) { |
54 | unsigned char c; | 54 | unsigned char c = 0; |
55 | read(fd, &c, sizeof(c)); | 55 | (void)read(fd, &c, sizeof(c)); |
56 | return c; | 56 | return c; |
57 | } | 57 | } |
58 | 58 | ||
59 | static uint Reader_ReadWord(int fd) { | 59 | static uint Reader_ReadWord(int fd) { |
60 | unsigned short s; | 60 | unsigned short s = 0; |
61 | read(fd, &s, sizeof(s)); | 61 | (void)read(fd, &s, sizeof(s)); |
62 | return letoh16(s); | 62 | return letoh16(s); |
63 | } | 63 | } |
64 | 64 | ||
65 | static uint Reader_ReadDWord(int fd) { | 65 | static uint Reader_ReadDWord(int fd) { |
66 | unsigned int i; | 66 | unsigned int i = 0; |
67 | read(fd, &i, sizeof(i)); | 67 | (void)read(fd, &i, sizeof(i)); |
68 | return letoh32(i); | 68 | return letoh32(i); |
69 | } | 69 | } |
70 | 70 | ||
71 | static char* Reader_ReadString(int fd, char *str) { | 71 | static char* Reader_ReadString(int fd, char *str) { |
72 | /*Note: still advances file buffer even if no string buffer supplied */ | ||
72 | int i = 0; | 73 | int i = 0; |
73 | char c = 1; | 74 | char ch = '\0'; |
74 | char *p = str; | 75 | char *p = str; |
75 | 76 | ||
76 | if (str) | 77 | while (i < VTX_STRING_MAX && (ch || i == 0)) |
77 | *str = 0; | 78 | { |
78 | 79 | if (read(fd, &ch, sizeof(ch) == sizeof(ch))) | |
79 | while (i < VTX_STRING_MAX && c) { | 80 | { |
80 | read(fd, &c, sizeof(c)); | 81 | if (str) |
81 | if (str) | 82 | *str++ = ch; |
82 | *str++ = c; | 83 | } |
83 | i++; | 84 | else |
85 | break; | ||
86 | i++; | ||
84 | } | 87 | } |
85 | |||
86 | if (str) | 88 | if (str) |
87 | *str = 0; | 89 | *str = '\0'; |
88 | 90 | ||
89 | return p; | 91 | return p; |
90 | } | 92 | } |