]> source.dussan.org Git - tigervnc.git/commitdiff
Be more paranoid about monitor info
authorPierre Ossman <ossman@cendio.se>
Thu, 23 Dec 2021 13:50:35 +0000 (14:50 +0100)
committerPierre Ossman <ossman@cendio.se>
Thu, 23 Dec 2021 13:50:35 +0000 (14:50 +0100)
These function are not guaranteed to succeed, and we've had reports that
they fail on ARM. So make sure we more properly check return values.

vncviewer/MonitorArrangement.cxx

index e075d17331fd20171664d96664787111f89ea8d1..055a91ccbbfe6b5deab82d70ee799b7bdefd625d 100644 (file)
@@ -406,6 +406,12 @@ std::string MonitorArrangement::get_monitor_name(int m)
 #elif defined(__APPLE__)
   CGDisplayCount count;
   CGDirectDisplayID displays[16];
+
+  CGDirectDisplayID displayID;
+  CFDictionaryRef info;
+  CFDictionaryRef dict;
+  CFIndex dict_len;
+
   std::string name;
 
   if (CGGetActiveDisplayList(16, displays, &count) != kCGErrorSuccess)
@@ -418,14 +424,20 @@ std::string MonitorArrangement::get_monitor_name(int m)
     return "";
 
   // Notice: Here we assume indices to be ordered the same as in FLTK (we rely on that in cocoa.mm as well).
-  CGDirectDisplayID displayID = displays[m];
+  displayID = displays[m];
+
+  info = IODisplayCreateInfoDictionary(CGDisplayIOServicePort(displayID),
+                                       kIODisplayOnlyPreferredName);
+  if (info == NULL)
+    return "";
 
-  CFDictionaryRef info = IODisplayCreateInfoDictionary(
-    /* display = */ CGDisplayIOServicePort(displayID),
-    /* options = */ kIODisplayOnlyPreferredName);
+  dict = (CFDictionaryRef) CFDictionaryGetValue(info, CFSTR(kDisplayProductName));
+  if (dict == NULL) {
+    CFRelease(info);
+    return "";
+  }
 
-  CFDictionaryRef dict = (CFDictionaryRef) CFDictionaryGetValue(info, CFSTR(kDisplayProductName));
-  CFIndex dict_len = CFDictionaryGetCount(dict);
+  dict_len = CFDictionaryGetCount(dict);
 
   if (dict_len > 0) {
     CFTypeRef * names = new CFTypeRef[dict_len];