diff options
| author | Matthias Melcher <github@matthiasm.com> | 2023-01-01 17:09:07 +0100 |
|---|---|---|
| committer | Matthias Melcher <github@matthiasm.com> | 2023-01-01 17:09:15 +0100 |
| commit | ab0d59220eb341daea4ac30bb4b506370de98eb0 (patch) | |
| tree | 0d10a140cb8c7bc5468cca8848a1c54b208c79c0 | |
| parent | bfe730ecbf94fb709928b735cf52c41e1e4d7ad3 (diff) | |
FLUID: Fixes size_t signedness warning
| -rw-r--r-- | fluid/Fluid_Image.cxx | 36 | ||||
| -rw-r--r-- | fluid/Fluid_Image.h | 4 |
2 files changed, 20 insertions, 20 deletions
diff --git a/fluid/Fluid_Image.cxx b/fluid/Fluid_Image.cxx index a72768014..4e985845b 100644 --- a/fluid/Fluid_Image.cxx +++ b/fluid/Fluid_Image.cxx @@ -54,14 +54,17 @@ static int gif_header_written = 0; static int bmp_header_written = 0; static int svg_header_written = 0; -/** Write the contents of the name() file as binary source code. */ -size_t Fluid_Image::write_static_binary() { +/** Write the contents of the name() file as binary source code. + \param fmt short name of file contents for error message + \return 0 if the file could not be opened or read */ +size_t Fluid_Image::write_static_binary(const char* fmt) { size_t nData = 0; enter_project_dir(); FILE *f = fl_fopen(name(), "rb"); leave_project_dir(); if (!f) { - return -1; + write_file_error(fmt); + return 0; } else { fseek(f, 0, SEEK_END); nData = ftell(f); @@ -77,14 +80,17 @@ size_t Fluid_Image::write_static_binary() { return nData; } -/** Write the contents of the name() file as textual source code. */ -size_t Fluid_Image::write_static_text() { +/** Write the contents of the name() file as textual source code. + \param fmt short name of file contents for error message + \return 0 if the file could not be opened or read */ +size_t Fluid_Image::write_static_text(const char* fmt) { size_t nData = 0; enter_project_dir(); FILE *f = fl_fopen(name(), "rb"); leave_project_dir(); if (!f) { - return -1; + write_file_error(fmt); + return 0; } else { fseek(f, 0, SEEK_END); nData = ftell(f); @@ -137,8 +143,7 @@ void Fluid_Image::write_static(int compressed) { gif_header_written = write_number; } write_c("static const unsigned char %s[] =\n", idata_name); - size_t nData = write_static_binary(); - if (nData == -1) write_file_error("GIF"); + size_t nData = write_static_binary("GIF"); write_c(";\n"); write_initializer("Fl_GIF_Image", "\"%s\", %s, %d", fl_filename_name(name()), idata_name, nData); } else if (compressed && strcmp(fl_filename_ext(name()), ".bmp")==0) { @@ -149,8 +154,7 @@ void Fluid_Image::write_static(int compressed) { gif_header_written = write_number; } write_c("static const unsigned char %s[] =\n", idata_name); - size_t nData = write_static_binary(); - if (nData == -1) write_file_error("BMP"); + size_t nData = write_static_binary("BMP"); write_c(";\n"); write_initializer("Fl_BMP_Image", "\"%s\", %s, %d", fl_filename_name(name()), idata_name, nData); } else if (img->count() > 1) { @@ -202,8 +206,7 @@ void Fluid_Image::write_static(int compressed) { jpeg_header_written = write_number; } write_c("static const unsigned char %s[] =\n", idata_name); - size_t nData = write_static_binary(); - if (nData == -1) write_file_error("JPEG"); + size_t nData = write_static_binary("JPEG"); write_c(";\n"); write_initializer("Fl_JPEG_Image", "\"%s\", %s, %d", fl_filename_name(name()), idata_name, nData); } else if (compressed && strcmp(fl_filename_ext(name()), ".png")==0) { @@ -214,8 +217,7 @@ void Fluid_Image::write_static(int compressed) { png_header_written = write_number; } write_c("static const unsigned char %s[] =\n", idata_name); - size_t nData = write_static_binary(); - if (nData == -1) write_file_error("PNG"); + size_t nData = write_static_binary("PNG"); write_c(";\n"); write_initializer("Fl_PNG_Image", "\"%s\", %s, %d", fl_filename_name(name()), idata_name, nData); } else if (strcmp(fl_filename_ext(name()), ".svg")==0 || strcmp(fl_filename_ext(name()), ".svgz")==0) { @@ -229,14 +231,12 @@ void Fluid_Image::write_static(int compressed) { } if (gzipped) { write_c("static const unsigned char %s[] =\n", idata_name); - size_t nData = write_static_binary(); - if (nData == -1) write_file_error("SVGZ"); + size_t nData = write_static_binary("SVGZ"); write_c(";\n"); write_initializer("Fl_SVG_Image", "\"%s\", %s, %ld", fl_filename_name(name()), idata_name, nData); } else { write_c("static const char %s[] =\n", idata_name); - size_t nData = write_static_text(); - if (nData == -1) write_file_error("SVG"); + write_static_text("SVG"); write_c(";\n"); write_initializer("Fl_SVG_Image", "\"%s\", %s", fl_filename_name(name()), idata_name); } diff --git a/fluid/Fluid_Image.h b/fluid/Fluid_Image.h index 705495b65..4845160c9 100644 --- a/fluid/Fluid_Image.h +++ b/fluid/Fluid_Image.h @@ -31,8 +31,8 @@ class Fluid_Image { protected: Fluid_Image(const char *name); // no public constructor ~Fluid_Image(); // no public destructor - size_t write_static_binary(); - size_t write_static_text(); + size_t write_static_binary(const char* fmt); + size_t write_static_text(const char* fmt); void write_static_rgb(const char* idata_name); public: int written; |
