Make sure we don't read past the end of global_edges when i = 0.
We are moving the elements backwards so at most n_global_edges - 1 elements can be moved.
==6818==ERROR: AddressSanitizer: dynamic-stack-buffer-overflow on address 0x7ffff888ae00 at pc 0x7fe4fd7be8ae bp 0x7ffff888ac90 sp 0x7ffff888a440
READ of size 96 at 0x7ffff888ae00 thread T0
#0 0x7fe4fd7be8ad in __interceptor_memmove (/lib/x86_64-linux-gnu/libasan.so.5+0x378ad)
#1 0x56524b2dba31 in Image::Fill(unsigned int, int, Polygon const&) /root/zoneminder/src/zm_image.cpp:2514
#2 0x56524af55530 in Monitor::DumpZoneImage(char const*) /root/zoneminder/src/zm_monitor.cpp:1510
#3 0x56524aeb38cb in main /root/zoneminder/src/zmu.cpp:574
#4 0x7fe4fb2b009a in __libc_start_main ../csu/libc-start.c:308
#5 0x56524aeb87a9 in _start (/root/zoneminder/cmake-build-relwithdebinfo-remote/src/zmu+0xf87a9)
(cherry picked from commit 63cea992a0)
VLAs (variable-length arrays) are a C99 feature and were never standardised for C++.
There are better alternatives in C++ (mainly std::vector). Enable the warnings
so no new ones can be introduced.
Make sure we don't read past the end of global_edges when i = 0.
We are moving the elements backwards so at most n_global_edges - 1 elements can be moved.
==6818==ERROR: AddressSanitizer: dynamic-stack-buffer-overflow on address 0x7ffff888ae00 at pc 0x7fe4fd7be8ae bp 0x7ffff888ac90 sp 0x7ffff888a440
READ of size 96 at 0x7ffff888ae00 thread T0
#0 0x7fe4fd7be8ad in __interceptor_memmove (/lib/x86_64-linux-gnu/libasan.so.5+0x378ad)
#1 0x56524b2dba31 in Image::Fill(unsigned int, int, Polygon const&) /root/zoneminder/src/zm_image.cpp:2514
#2 0x56524af55530 in Monitor::DumpZoneImage(char const*) /root/zoneminder/src/zm_monitor.cpp:1510
#3 0x56524aeb38cb in main /root/zoneminder/src/zmu.cpp:574
#4 0x7fe4fb2b009a in __libc_start_main ../csu/libc-start.c:308
#5 0x56524aeb87a9 in _start (/root/zoneminder/cmake-build-relwithdebinfo-remote/src/zmu+0xf87a9)
The polygon vertex coordinated of extra_zone are directly parsed from user input.
Clip the resulting polygon to the image size so we don't try to draw outside of the image.
This is already done for zone polygons stored and loaded from the DB.
Using the Sutherland-Hodgman algorithms convex and concave subject polygons can be clipped
by convex clip polygons.
For now we only need clipping to rectangles (Box), so limit our implementation to that. If needed this can be
trivially extended to convex clip polygons (a check whether the clip polygon is actually convex has to be added).
If convex clip polygons are needed we have to switch to e.g the Vatti algorithm.