MCDE dtphoto: M_PI and the extruded front colour, for a strict POSIX build

`_POSIX_C_SOURCE 200809L` (line 16) turns off _XOPEN_SOURCE and
_NETBSD_SOURCE, and NetBSD's math.h carries M_PI only for those: all
sixteen uses were an undeclared identifier.  The guard defines the value
every libm has, as lib/McdeSys/test_audio.c already does.

OpExtrude passed a compound literal to memcpy.  Its commas sit between
memcpy's own argument commas, so _FORTIFY_SOURCE counts five arguments
and refuses: "macro memcpy passed 5 arguments, but takes just 3".  A
named array keeps the call a three-argument call.

Both are what a pkgsrc build of wm/mcde stops on, before any binary:

  dtphoto.c:4019:31: error: 'M_PI' undeclared (first use in this function)
  dtphoto.c:8416:53: error: macro "memcpy" passed 5 arguments, but takes just 3

Verified: the file compiles with the build's own flags,
`cc -fsyntax-only -std=gnu11 -D_POSIX_C_SOURCE=200809L -D_FORTIFY_SOURCE=2
-O2` -> exit 0, and with -Wall -Wextra no warning points at the new lines.
This commit is contained in:
lotherk committed 2026-11-22 20:13:28 +00:00
1 parent 7c9347dc9b
commit 4e51d6dd65
1 file changed
+16 -4
+16 -4
View File
@@ -53,6 +53,14 @@
#include <Mcde/McdeSys.h>
#include <Mcde/Thumb.h>
/* M_PI is not in POSIX: math.h carries it only for _XOPEN_SOURCE or
* _NETBSD_SOURCE, and _POSIX_C_SOURCE 200809L (line 16) turns both off.
* Guarded, so it stays quiet where the header has it. Same as
* lib/McdeSys/test_audio.c does. */
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif
#define MAXMENUS 16
#define MAXITEMS 80
#define MAXDEPTH 4
@@ -8398,7 +8406,7 @@ OpExtrude(int cell, int depth, int solidFront)
{
unsigned char *rgb, *out;
int w, h, x, y, bx, by, c;
unsigned char br, bg, bb;
unsigned char br, bg, bb, front[3];
if (cell < 2) cell = 2;
if (depth < 1) depth = 1;
@@ -8409,11 +8417,15 @@ OpExtrude(int cell, int depth, int solidFront)
return;
}
PixelToRGB(bgPixel, &br, &bg, &bb);
/* A compound literal here would put its commas between memcpy's
* own argument commas: _FORTIFY_SOURCE sees five arguments, not
* three. A named array keeps the call a three-argument call. */
front[0] = solidFront ? br : 0;
front[1] = solidFront ? bg : 0;
front[2] = solidFront ? bb : 0;
for (y = 0; y < h; y++)
for (x = 0; x < w; x++)
memcpy(out + ((size_t) y * w + x) * 3, (unsigned char[]) {
solidFront ? br : 0, solidFront ? bg : 0,
solidFront ? bb : 0 }, 3);
memcpy(out + ((size_t) y * w + x) * 3, front, 3);
for (by = 0; by < h; by += cell)
for (bx = 0; bx < w; bx += cell) {
int n = NoiseAt(bx, by, 5u);