From fd66cdb200c6cba27d17d6b1d57eb7ddb63deae2 Mon Sep 17 00:00:00 2001 From: lotherk Date: Sun, 22 Nov 2026 05:50:22 +0000 Subject: [PATCH] MCDE dtpaint: Ctrl+S kept the path and title (t0704 follow-up) DoSave(curPath) passed curPath as both the destination and the source of snprintf, which is undefined; glibc emptied it, so after Ctrl+S the title fell back to 'untitled' and the next Save opened Save As again. Copy only when the pointers differ. Found while verifying the PseudoColor path on Xvfb depth 8 (4-colour BMP round trip exact, selftest PASS); recorded in AGENTS.md. --- AGENTS.md | 5 ++++- programs/dtpaint/dtpaint.c | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index efb1fffe..f8e8b6a4 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -80,7 +80,10 @@ narratives and test notes, is `docs/reference/mcde-agents-history-2026-11-13.txt and refreshed after a load, and Open/Save/Invert convert colours through the visual's masks on TrueColor (or in batches otherwise), never one X round trip per pixel (measured 2026-11-21: open 18.3 s -> 0.02 s, invert - 14.9 s -> 0.05 s, save 6.3 s -> 0.23 s on a 1024x768 BMP). + 14.9 s -> 0.05 s, save 6.3 s -> 0.23 s on a 1024x768 BMP; PseudoColor + measured 2026-11-22 on Xvfb depth 8: 4-colour BMP round trip exact, + selftest PASS -- a picture with more colours than the 256-cell colormap + holds loses the excess, as any 8-bit paint must). McdeSys has a catalog too (`lib/McdeSys/mcdesys.msg`, `lib/McdeSys/ text.c`, `mcde_sys_msg`): common.c's tool errors ask it for their sentence (messages 1-9: not there, cannot start, failed with status, no pipe, no diff --git a/programs/dtpaint/dtpaint.c b/programs/dtpaint/dtpaint.c index ec319d18..9c0d819b 100644 --- a/programs/dtpaint/dtpaint.c +++ b/programs/dtpaint/dtpaint.c @@ -1109,7 +1109,10 @@ static void DoSave(const char *path) { if (SaveBMP(path) == 0) { - snprintf(curPath, sizeof curPath, "%s", path); + /* C_SAVE passes curPath itself; snprintf onto the same buffer + * is undefined and emptied it (the title fell back to untitled) */ + if (path != curPath) + snprintf(curPath, sizeof curPath, "%s", path); dirty = 0; SetTitle(); } else {