On Thu, 22 Oct 2026 12:32:03 GMT, Matthias Baesken <[email protected]> wrote:

> The gcc static analyzer reports this issue :
> 
> `src/java.desktop/unix/native/common/java2d/x11/X11Renderer.c:86:17: warning: 
> use of possibly-NULL 'malloc((long unsigned int)newMax * 4)' where non-null 
> expected [CWE-690] [-Wanalyzer-possible-null-argument]`
> 
> Seems we miss NULL checks in the XDHD_ADD_POINT macro (for malloc).
> 
> While at it, should I NULL check realloc too?
> 
> ---------
> - [x] I confirm that I make this contribution in accordance with the [OpenJDK 
> Interim AI Policy](https://openjdk.org/legal/ai).

src/java.desktop/unix/native/common/java2d/x11/X11Renderer.c line 97:

> 95:         _pnts->x = X;                                                     
>   \
> 96:         _pnts->y = Y;                                                     
>   \
> 97:         (PTR)->npoints = _npnts + 1;                                      
>   \

This change doesn't seem right to me.

If `malloc` fails, the `NULL` check only skips `memcpy`. The macro still 
assigns `NULL` to `_pnts`, updates `maxpoints`, and writes the new point 
through an invalid pointer, so a crash remains possible.

The `realloc` path has the same problem and also loses the pointer to the 
original allocation on failure.

At minimum, we should store the result of `malloc`/`realloc` in a temporary 
pointer and update the structure only on success. (and check if allocation 
failure is handled safely by other code)

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/33513#discussion_r4352834894

Reply via email to