summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPierre-Loup A. Griffais <git@plagman.net>2020-06-06 15:03:08 -0700
committerPierre-Loup A. Griffais <git@plagman.net>2020-11-01 13:45:02 -0800
commit33042c835583b77c31f38f33e5560e596a416662 (patch)
tree0a56d2f6fcacfd9132b2436a55c5e356306022c8
parent540c5674722c1f569e9089db14ef07554ef48c16 (diff)
Break down memory allocation logic and fix overallocating for UTF8.
We need up to 3 bytes per character in UTF8 mode, not 4.
-rw-r--r--xprop.c11
1 files changed, 10 insertions, 1 deletions
diff --git a/xprop.c b/xprop.c
index dc7fa0b..b3835d5 100644
--- a/xprop.c
+++ b/xprop.c
@@ -767,16 +767,25 @@ Format_Icons (const unsigned long *icon, int len)
while (icon < end)
{
unsigned long width, height;
+ unsigned int icon_pixel_bytes;
+ unsigned int icon_line_bytes;
int w, h;
int offset;
width = *icon++;
height = *icon++;
+ icon_pixel_bytes = 1;
+ if (is_utf8_locale())
+ icon_pixel_bytes = 3; /* Up to 3 bytes per character in that mode. */
+
+ /* Initial tab, pixels, and newline. */
+ icon_line_bytes = 8 + width * icon_pixel_bytes + 1;
+
offset = (tail - result);
alloced += 80; /* For the header */
- alloced += (width*4 + 8) * height; /* For the rows (plus padding) */
+ alloced += icon_line_bytes * height; /* For the rows */
result = realloc (result, alloced);
if (!result)