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) |
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 { #define VTX_STRING_MAX 254 static uint Reader_ReadByte(int fd) { - unsigned char c; - read(fd, &c, sizeof(c)); + unsigned char c = 0; + (void)read(fd, &c, sizeof(c)); return c; } static uint Reader_ReadWord(int fd) { - unsigned short s; - read(fd, &s, sizeof(s)); + unsigned short s = 0; + (void)read(fd, &s, sizeof(s)); return letoh16(s); } static uint Reader_ReadDWord(int fd) { - unsigned int i; - read(fd, &i, sizeof(i)); + unsigned int i = 0; + (void)read(fd, &i, sizeof(i)); return letoh32(i); } static char* Reader_ReadString(int fd, char *str) { + /*Note: still advances file buffer even if no string buffer supplied */ int i = 0; - char c = 1; + char ch = '\0'; char *p = str; - if (str) - *str = 0; - - while (i < VTX_STRING_MAX && c) { - read(fd, &c, sizeof(c)); - if (str) - *str++ = c; - i++; + while (i < VTX_STRING_MAX && (ch || i == 0)) + { + if (read(fd, &ch, sizeof(ch) == sizeof(ch))) + { + if (str) + *str++ = ch; + } + else + break; + i++; } - if (str) - *str = 0; + *str = '\0'; return p; } |