diff --git a/launcher/src/logger/crash-report.cpp b/launcher/src/logger/crash-report.cpp index 7894c5c87b..9f5cd12feb 100644 --- a/launcher/src/logger/crash-report.cpp +++ b/launcher/src/logger/crash-report.cpp @@ -70,15 +70,21 @@ struct CrashReport final : Frame { }; // Show Crash Report Dialog +static void redirect_file(FILE *file, const char *mode) { + const FILE *ret = freopen("/dev/null", mode, file); + if (!ret) { + IMPOSSIBLE(); + } +} void show_report(const char *log_filename) { // Fork const pid_t pid = fork(); if (pid == 0) { // Child setsid(); - ALLOC_CHECK(freopen("/dev/null", "w", stdout)); - ALLOC_CHECK(freopen("/dev/null", "w", stderr)); - ALLOC_CHECK(freopen("/dev/null", "r", stdin)); + redirect_file(stdout, "w"); + redirect_file(stderr, "w"); + redirect_file(stdin, "r"); CrashReport ui(log_filename); ui.run(); exit(EXIT_SUCCESS); diff --git a/launcher/src/util/env.cpp b/launcher/src/util/env.cpp index fa6a564742..d7dad887bb 100644 --- a/launcher/src/util/env.cpp +++ b/launcher/src/util/env.cpp @@ -2,8 +2,8 @@ #include "util.h" +#include #include -#include #include // $PATH @@ -41,7 +41,9 @@ void setup_home() { } else { // Set Home To Current Directory, So World Data Is Stored There char *launch_directory = getcwd(nullptr, 0); - ALLOC_CHECK(launch_directory); + if (launch_directory == nullptr) { + IMPOSSIBLE(); + } home = launch_directory; free(launch_directory); } diff --git a/libreborn/include/libreborn/util.h b/libreborn/include/libreborn/util.h index f5a3934fb6..858fb3f66d 100644 --- a/libreborn/include/libreborn/util.h +++ b/libreborn/include/libreborn/util.h @@ -5,25 +5,8 @@ #include "log.h" -// Check Memory Allocation -#define ALLOC_CHECK(obj) \ - { \ - if ((obj) == nullptr) { \ - ERR("Memory Allocation Failed"); \ - } \ - } - // Align Number -#define ALIGN_UP(x, alignment) \ - ({ \ - int _align_x = (x); \ - int _align_alignment = (alignment); \ - int _align_diff = _align_x % _align_alignment; \ - if (_align_diff > 0) { \ - _align_x += (_align_alignment - _align_diff); \ - } \ - _align_x; \ - }) +int align_up(int x, int alignment); // Hook Library Function #define HOOK(name, return_type, args) \ diff --git a/libreborn/src/util/util.cpp b/libreborn/src/util/util.cpp index 29b9bb26af..9898c20c19 100644 --- a/libreborn/src/util/util.cpp +++ b/libreborn/src/util/util.cpp @@ -7,6 +7,15 @@ #include #include +// Align Number +int align_up(int x, const int alignment) { + const int diff = x % alignment; + if (diff > 0) { + x += (alignment - diff); + } + return x; +} + // Safe Version Of pipe() Pipe::Pipe(): read(-1), write(-1) { int out[2]; diff --git a/media-layer/trampoline/src/GLESv1_CM.cpp b/media-layer/trampoline/src/GLESv1_CM.cpp index 62e1e7a4dc..1cbdbf9b22 100644 --- a/media-layer/trampoline/src/GLESv1_CM.cpp +++ b/media-layer/trampoline/src/GLESv1_CM.cpp @@ -302,7 +302,7 @@ static int get_texture_size(const GLsizei width, const GLsizei height, const GLe int alignment; media_glGetIntegerv(is_upload ? GL_UNPACK_ALIGNMENT : GL_PACK_ALIGNMENT, &alignment); // Round - line_size = ALIGN_UP(line_size, alignment); + line_size = align_up(line_size, alignment); } // Return return line_size * height; diff --git a/mods/src/atlas/atlas.cpp b/mods/src/atlas/atlas.cpp index e3db3b40f4..9d5e116643 100644 --- a/mods/src/atlas/atlas.cpp +++ b/mods/src/atlas/atlas.cpp @@ -130,7 +130,7 @@ static void generate_atlas(Minecraft *minecraft) { int alignment; media_glGetIntegerv(GL_PACK_ALIGNMENT, &alignment); // Round - line_size = ALIGN_UP(line_size, alignment); + line_size = align_up(line_size, alignment); } Texture texture; texture.width = atlas_texture_size; diff --git a/mods/src/misc/misc.cpp b/mods/src/misc/misc.cpp index e990ed7d0e..83cd8aea5f 100644 --- a/mods/src/misc/misc.cpp +++ b/mods/src/misc/misc.cpp @@ -215,7 +215,6 @@ static AppPlatform_readAssetFile_return_value AppPlatform_readAssetFile_injectio // Read File const std::streamoff len = stream.tellg(); char *buf = new char[len]; - ALLOC_CHECK(buf); stream.seekg(0, std::ifstream::beg); stream.read(buf, len); stream.close(); diff --git a/mods/src/screenshot/screenshot.cpp b/mods/src/screenshot/screenshot.cpp index f3b498bb27..be27959bf6 100644 --- a/mods/src/screenshot/screenshot.cpp +++ b/mods/src/screenshot/screenshot.cpp @@ -79,13 +79,12 @@ void screenshot_take(Gui *gui) { int alignment; media_glGetIntegerv(GL_PACK_ALIGNMENT, &alignment); // Round - line_size = ALIGN_UP(line_size, alignment); + line_size = align_up(line_size, alignment); } const int size = height * line_size; // Read Pixels unsigned char *pixels = new unsigned char[size]; - ALLOC_CHECK(pixels); media_glReadPixels(x, y, width, height, GL_RGBA, GL_UNSIGNED_BYTE, pixels); // Save Image diff --git a/mods/src/textures/textures.cpp b/mods/src/textures/textures.cpp index a04a79759a..fdf1bd5d72 100644 --- a/mods/src/textures/textures.cpp +++ b/mods/src/textures/textures.cpp @@ -51,7 +51,7 @@ static int get_line_size(const int width) { int alignment; media_glGetIntegerv(GL_UNPACK_ALIGNMENT, &alignment); // Round - line_size = ALIGN_UP(line_size, alignment); + line_size = align_up(line_size, alignment); } return line_size; }