diff options
author | Christoph M. Becker <cmbecker69@gmx.de> | 2020-05-05 12:02:45 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-05-05 18:02:45 +0800 |
commit | 3dd0e308cbd2c24fde2fc9e9b707181252a2de95 (patch) | |
tree | 1480aba50c5fa0251cbd32ed17664882281e9203 /tests/gdimagestringft | |
parent | 188aa091e1c87ded33707f738753430dcd848bee (diff) | |
download | libgd-3dd0e308cbd2c24fde2fc9e9b707181252a2de95.tar.gz |
Fix #615: gdImageStringFT() fails for empty strings as of libgd 2.3.0 (#633)
We change the return type of `textLayout()` to `ssize_t`, and signal
failure by returning `-1`, so that laying out an empty string is no
longer handled as failure. We make sure that no overflow occurs,
assuming that all `int` values can be fully represented as `ssize_t`.
Diffstat (limited to 'tests/gdimagestringft')
-rw-r--r-- | tests/gdimagestringft/.gitignore | 1 | ||||
-rw-r--r-- | tests/gdimagestringft/CMakeLists.txt | 1 | ||||
-rw-r--r-- | tests/gdimagestringft/Makemodule.am | 1 | ||||
-rw-r--r-- | tests/gdimagestringft/bug00615.c | 25 |
4 files changed, 28 insertions, 0 deletions
diff --git a/tests/gdimagestringft/.gitignore b/tests/gdimagestringft/.gitignore index f9f01f0..efe5e61 100644 --- a/tests/gdimagestringft/.gitignore +++ b/tests/gdimagestringft/.gitignore @@ -1 +1,2 @@ +/bug00615 /gdimagestringft_bbox diff --git a/tests/gdimagestringft/CMakeLists.txt b/tests/gdimagestringft/CMakeLists.txt index f46b900..42868a2 100644 --- a/tests/gdimagestringft/CMakeLists.txt +++ b/tests/gdimagestringft/CMakeLists.txt @@ -1,5 +1,6 @@ IF(FREETYPE_FOUND) LIST(APPEND TESTS_FILES + bug00615 gdimagestringft_bbox ) ENDIF(FREETYPE_FOUND) diff --git a/tests/gdimagestringft/Makemodule.am b/tests/gdimagestringft/Makemodule.am index 0dfe26f..a62081f 100644 --- a/tests/gdimagestringft/Makemodule.am +++ b/tests/gdimagestringft/Makemodule.am @@ -1,5 +1,6 @@ if HAVE_LIBFREETYPE libgd_test_programs += \ + gdimagestringft/bug00615 \ gdimagestringft/gdimagestringft_bbox endif diff --git a/tests/gdimagestringft/bug00615.c b/tests/gdimagestringft/bug00615.c new file mode 100644 index 0000000..0da51da --- /dev/null +++ b/tests/gdimagestringft/bug00615.c @@ -0,0 +1,25 @@ +/** + * Test that rendering an empty string does not fail + * + * Rendering an empty string with gdImageStringFT() is not supposed to fail; + * it is just a no-op. + * + * See <https://github.com/libgd/libgd/issues/615> + */ + +#include "gd.h" +#include "gdtest.h" + +int main() +{ + gdImagePtr im = gdImageCreate(100, 100); + + int rect[8]; + int fg = gdImageColorAllocate(im, 255, 255, 255); + char *path = gdTestFilePath("freetype/DejaVuSans.ttf"); + char *res = gdImageStringFT(im, rect, fg, path, 12, 0, 10, 10, ""); + + gdTestAssert(res == NULL); + + return gdNumFailures(); +} |