GNU bug report logs - #76691
`display-monitor-attributes-list` not working properly on macOS

Previous Next

Package: emacs;

Reported by: Ruiyang Wu <ywwry66 <at> gmail.com>

Date: Sun, 2 Mar 2025 21:00:03 UTC

Severity: normal

Tags: confirmed, patch

Merged with 76051

Found in versions 29.4, 30.1, 31.0.50

Done: Alan Third <alan <at> idiocy.org>

Full log


View this message in rfc822 format

From: Robert Pluim <rpluim <at> gmail.com>
To: Ship Mints <shipmints <at> gmail.com>
Cc: 76691 <at> debbugs.gnu.org, Juri Linkov <juri <at> linkov.net>, Ruiyang Wu <ywwry66 <at> gmail.com>, Stefan Kangas <stefankangas <at> gmail.com>
Subject: bug#76691: `display-monitor-attributes-list` not working properly on macOS
Date: Thu, 06 Mar 2025 11:08:43 +0100
>>>>> On Wed, 5 Mar 2025 06:38:05 -0500, Ship Mints <shipmints <at> gmail.com> said:
 
    Ship>  #ifdef NS_IMPL_COCOA
    Ship> -      m->name = ns_screen_name (did);
    Ship> +      m->name = NULL;
    Ship> +      if ([s respondsToSelector:@selector(localizedName)])
    Ship> +        {
    Ship> +	  NSString *name = [s valueForKey:@"localizedName"];
    Ship> +	  if (name != NULL)
    Ship> +	    {
    Ship> +	      m->name = xmalloc ([name lengthOfBytesUsingEncoding: NSUTF8StringEncoding]);
    Ship> +	      strcpy(m->name, [name UTF8String]);
    Ship> +	    }

The reason it was crashing for me is that the xmalloc doesnʼt account
for the terminating '\0', ie we need

    m->name = xmalloc ([name lengthOfBytesUsingEncoding: NSUTF8StringEncoding] + 1);

or just

    m->name = xstrdup ([name UTF8String]);

    Ship> +        }
    Ship> +      /* If necessary, synthesize a name of the following form:
    Ship> +	  %dx%d@%d,%d width height x y. */
    Ship> +      if (m->name == NULL)
    Ship> +	{
    Ship> +	  char buf[25]; /* sufficient for 12345x78901 <at> 34567,90123 */
    Ship> +	  snprintf (buf, sizeof(buf), "%ux%u@%d,%d",
    Ship> +		    m->work.width, m->work.height, m->work.x, m->work.y);
    Ship> +	  m->name = xstrdup (buf);
    Ship> +	}


Robert
-- 




This bug report was last modified 12 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.