(RPNG) Make sure we don't use stdio/fprintf unless DEBUG is defined

This commit is contained in:
twinaphex 2020-08-22 16:07:03 +02:00
parent deafd70934
commit 5cc4d0da0f
2 changed files with 31 additions and 15 deletions

View File

@ -20,7 +20,9 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/ */
#ifdef DEBUG
#include <stdio.h> #include <stdio.h>
#endif
#include <stdint.h> #include <stdint.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
@ -132,7 +134,6 @@ static INLINE uint32_t dword_be(const uint8_t *buf)
static bool png_process_ihdr(struct png_ihdr *ihdr) static bool png_process_ihdr(struct png_ihdr *ihdr)
{ {
unsigned i; unsigned i;
bool ret = true;
switch (ihdr->color_type) switch (ihdr->color_type)
{ {
@ -140,7 +141,12 @@ static bool png_process_ihdr(struct png_ihdr *ihdr)
case PNG_IHDR_COLOR_GRAY_ALPHA: case PNG_IHDR_COLOR_GRAY_ALPHA:
case PNG_IHDR_COLOR_RGBA: case PNG_IHDR_COLOR_RGBA:
if (ihdr->depth != 8 && ihdr->depth != 16) if (ihdr->depth != 8 && ihdr->depth != 16)
GOTO_END_ERROR(); {
#ifdef DEBUG
fprintf(stderr, "[RPNG]: Error in line %d.\n", __LINE__);
#endif
return false;
}
break; break;
case PNG_IHDR_COLOR_GRAY: case PNG_IHDR_COLOR_GRAY:
{ {
@ -157,7 +163,12 @@ static bool png_process_ihdr(struct png_ihdr *ihdr)
} }
if (!correct_bpp) if (!correct_bpp)
GOTO_END_ERROR(); {
#ifdef DEBUG
fprintf(stderr, "[RPNG]: Error in line %d.\n", __LINE__);
#endif
return false;
}
} }
break; break;
case PNG_IHDR_COLOR_PLT: case PNG_IHDR_COLOR_PLT:
@ -175,11 +186,19 @@ static bool png_process_ihdr(struct png_ihdr *ihdr)
} }
if (!correct_bpp) if (!correct_bpp)
GOTO_END_ERROR(); {
#ifdef DEBUG
fprintf(stderr, "[RPNG]: Error in line %d.\n", __LINE__);
#endif
return false;
}
} }
break; break;
default: default:
GOTO_END_ERROR(); #ifdef DEBUG
fprintf(stderr, "[RPNG]: Error in line %d.\n", __LINE__);
#endif
return false;
} }
#ifdef RPNG_TEST #ifdef RPNG_TEST
@ -192,10 +211,14 @@ static bool png_process_ihdr(struct png_ihdr *ihdr)
#endif #endif
if (ihdr->compression != 0) if (ihdr->compression != 0)
GOTO_END_ERROR(); {
#ifdef DEBUG
fprintf(stderr, "[RPNG]: Error in line %d.\n", __LINE__);
#endif
return false;
}
end: return true;
return ret;
} }
static void png_reverse_filter_copy_line_rgb(uint32_t *data, static void png_reverse_filter_copy_line_rgb(uint32_t *data,

View File

@ -27,13 +27,6 @@
#include <filters.h> #include <filters.h>
#include <formats/rpng.h> #include <formats/rpng.h>
#undef GOTO_END_ERROR
#define GOTO_END_ERROR() do { \
fprintf(stderr, "[RPNG]: Error in line %d.\n", __LINE__); \
ret = false; \
goto end; \
} while (0)
#ifndef ARRAY_SIZE #ifndef ARRAY_SIZE
#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0])) #define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
#endif #endif