From 3c4021d7d63ab99e528de6ac5b937f9ce59f7354 Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Sun, 19 Oct 2014 20:01:01 -0400 Subject: [PATCH] Fixed a potential bug in the WM_SETFONT handling. --- wintable/main.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/wintable/main.c b/wintable/main.c index d99e820..a17e45b 100644 --- a/wintable/main.c +++ b/wintable/main.c @@ -33,7 +33,7 @@ struct table { static void drawItems(struct table *t, HDC dc) { - HFONT prevfont; + HFONT thisfont, prevfont; TEXTMETRICW tm; LONG y; intptr_t i; @@ -41,7 +41,8 @@ static void drawItems(struct table *t, HDC dc) if (GetClientRect(t->hwnd, &r) == 0) abort(); - prevfont = (HFONT) SelectObject(dc, t->font); + thisfont = t->font; // in case WM_SETFONT happens before we return + prevfont = (HFONT) SelectObject(dc, thisfont); if (prevfont == NULL) abort(); if (GetTextMetricsW(dc, &tm) == 0) @@ -68,7 +69,7 @@ static void drawItems(struct table *t, HDC dc) TextOutW(dc, r.left, y, L"Item", 4); y += tm.tmHeight; } - if (SelectObject(dc, prevfont) != (HGDIOBJ) (t->font)) + if (SelectObject(dc, prevfont) != (HGDIOBJ) (thisfont)) abort(); }