@@ -56,7 +56,7 @@ readLine(char *str, int n, FreeImageIO *io, fi_handle handle) {
5656 do {
5757 count = io->read_proc (&c, 1 , 1 , handle);
5858 str[i++] = c;
59- } while ((c != ' \n ' ) && (i < n));
59+ } while ((c != ' \n ' ) && (i < n - 1 ));
6060 if (count <= 0 )
6161 return nullptr ;
6262 str[i] = ' \0 ' ;
@@ -88,34 +88,31 @@ Read an XBM file into a buffer
8888static const char *
8989readXBMFile (FreeImageIO *io, fi_handle handle, int *widthP, int *heightP, std::unique_ptr<void , decltype (&free)> &dataP) {
9090 char line[MAX_LINE], name_and_type[MAX_LINE];
91- char * ptr;
92- char * t ;
91+ char * ptr{} ;
92+ char *t{} ;
9393 int version = 0 ;
9494 size_t bytes, bytes_per_line, raster_length;
9595 int v, padding;
9696 int c1, c2, value1, value2;
9797 int hex_table[256 ];
98- FIBOOL found_declaration;
98+ bool found_declaration{}; // haven't found it yet; haven't even looked
9999 /* in scanning through the bitmap file, we have found the first
100100 line of the C declaration of the array (the "static char ..."
101101 or whatever line)
102102 */
103- FIBOOL eof; // we've encountered end of file while searching file
103+ bool eof{} ; // we've encountered end of file while searching file
104104
105105 *widthP = *heightP = -1 ;
106106
107- found_declaration = FALSE ; // haven't found it yet; haven't even looked
108- eof = FALSE ; // haven't encountered end of file yet
109-
110107 while (!found_declaration && !eof) {
111108
112109 if (!readLine (line, MAX_LINE, io, handle)) {
113- eof = TRUE ;
110+ eof = true ;
114111 }
115112 else {
116113 if (strlen (line) == MAX_LINE - 1 )
117114 return ( ERR_XBM_LINE );
118- if (sscanf (line, " #define %s %d" , name_and_type, &v) == 2 ) {
115+ if (sscanf_s (line, " #define %s %d" , name_and_type, MAX_LINE , &v) == 2 ) {
119116 if ((t = strrchr (name_and_type, ' _' )) == nullptr )
120117 t = name_and_type;
121118 else
@@ -127,17 +124,17 @@ readXBMFile(FreeImageIO *io, fi_handle handle, int *widthP, int *heightP, std::u
127124 continue ;
128125 }
129126
130- if (sscanf (line, " static short %s = {" , name_and_type) == 1 ) {
127+ if (sscanf_s (line, " static short %s = {" , name_and_type, MAX_LINE ) == 1 ) {
131128 version = 10 ;
132- found_declaration = TRUE ;
129+ found_declaration = true ;
133130 }
134- else if (sscanf ( line, " static char %s = {" , name_and_type ) == 1 ) {
131+ else if (sscanf_s ( line, " static char %s = {" , name_and_type, MAX_LINE ) == 1 ) {
135132 version = 11 ;
136- found_declaration = TRUE ;
133+ found_declaration = true ;
137134 }
138- else if (sscanf (line, " static unsigned char %s = {" , name_and_type ) == 1 ) {
135+ else if (sscanf_s (line, " static unsigned char %s = {" , name_and_type, MAX_LINE ) == 1 ) {
139136 version = 11 ;
140- found_declaration = TRUE ;
137+ found_declaration = true ;
141138 }
142139 }
143140 }
@@ -292,7 +289,7 @@ MimeType() {
292289static FIBOOL DLL_CALLCONV
293290Validate (FreeImageIO *io, fi_handle handle) {
294291 char magic[8 ];
295- if (readLine (magic, 7 , io, handle)) {
292+ if (readLine (magic, 8 , io, handle)) {
296293 if (strcmp (magic, " #define" ) == 0 )
297294 return TRUE ;
298295 }
0 commit comments