Should `cairo_pdf_version_to_string` check for negative values?
While debugging https://github.com/pygobject/pycairo/pull/243#issuecomment-1153079380 I found that passing -1
(which is invalid) the function cairo_pdf_version_to_string
returns a memory address rather than NULL
as documented. A sample C program:
#include "cairo.h"
#include "cairo-pdf.h"
#include <stdio.h>
int main(){
const char* a = cairo_pdf_version_to_string (-1);
if (a == NULL){
printf("yes\n");
} else {
printf("%p no\n", a);
}
}
On my system (Windows 11, MSVC 2022), this prints:
00000A6F6E207025 no
which isn't NULL and instead some random address. I think this is because the code https://gitlab.freedesktop.org/cairo/cairo/-/blob/master/src/cairo-pdf-surface.c#L782 returns array[-1]
which would be the previous address of the array which is wrong to return. I think the above "if condition" there should check whether the number passed is negative and return NULL
if it's so.