XpmCreateBufferFromXpmImage fails with XpmNoMemory
In WriteColors() in CrBufFrI.c,
if( *data_size >= UINT_MAX-l || *data_size + l <= *used_size || (*data_size + l - *used_size) <= sizeof(buf)) return(XpmNoMemory);
The last line of this check should always evaluate to true, making WriteColors, and XpmCreateBufferFromXpmImage fail.
Using the same image creation code, and replacing XpmCreateBufferFromXpmImage with XpmWriteFileFromXpmImage succeeds.
A google search for the function name brought up this bug report from 2010. It looks like the same issue, and the bug was closed for inactivity.