From cc556bc19b8c88fd0415a8a1f2a0740f796e04e5 Mon Sep 17 00:00:00 2001 From: MihailRis Date: Thu, 23 Nov 2023 19:26:40 +0300 Subject: [PATCH] GCC warnings fix --- src/coders/png.cpp | 6 +++++- src/files/binary_io.cpp | 15 ++++++++++++--- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/coders/png.cpp b/src/coders/png.cpp index e15e0a98..fd8baa32 100644 --- a/src/coders/png.cpp +++ b/src/coders/png.cpp @@ -105,7 +105,11 @@ ImageData* _png_load(const char* file){ if (!(f = fopen(file, "r"))) { return nullptr; } - fread(header, 1, 8, f); + if (fread(header, 1, 8, f) < 8) { + fclose(f); + return nullptr; + } + is_png = !png_sig_cmp(header, 0, 8); if (!is_png) { fclose(f); diff --git a/src/files/binary_io.cpp b/src/files/binary_io.cpp index 0fb18b3b..696437d0 100644 --- a/src/files/binary_io.cpp +++ b/src/files/binary_io.cpp @@ -60,7 +60,12 @@ void BinaryWriter::putInt64(int64_t val) { } void BinaryWriter::putFloat32(float val) { - putInt32(*((uint32_t*)&val)); + union { + int32_t vali32; + float valfloat; + } value; + value.valfloat = val; + putInt32(value.vali32); } BinaryReader::BinaryReader(const ubyte* data, size_t size) @@ -122,8 +127,12 @@ int64_t BinaryReader::getInt64() { } float BinaryReader::getFloat32() { - int32_t value = getInt32(); - return *(float*)(&value); + union { + int32_t vali32; + float valfloat; + } value; + value.vali32 = getInt32(); + return value.valfloat; } string BinaryReader::getString() {