Преглед изворни кода

libcompat: Try to use NSIG when sys_siglist is defined

We cannot compute the size of the array with sizeof when the only thing
we have is an extern declaration. Try to use NSIG, and fallback to 32
items in case it is not defined.

Prompted-by: Igor Pashev <pashev.igor@gmail.com>
Guillem Jover пре 11 година
родитељ
комит
02eabc9981
2 измењених фајлова са 9 додато и 1 уклоњено
  1. 3 0
      debian/changelog
  2. 6 1
      lib/compat/strsignal.c

+ 3 - 0
debian/changelog

@@ -11,6 +11,9 @@ dpkg (1.18.2) UNRELEASED; urgency=low
   * Add support for ignoring built-in build dependencies and conflicts
     with the new «dpkg-buildpackage --ignore-builtin-builddeps» and
     «dpkg-checkbuilddeps -I» options. Closes: #480638, #571671
+  * When sys_siglist is defined in the system, try to use NSIG as we cannot
+    compute the array size with sizeof(). If NSIG is missing fallback to 32
+    items. Prompted by Igor Pashev <pashev.igor@gmail.com>.
   * Perl modules:
     - Remove non-functional timezone name support from
       Dpkg::Changelog::Entry::Debian.

+ 6 - 1
lib/compat/strsignal.c

@@ -54,7 +54,12 @@ const char *const sys_siglist[] = {
 	"SIGTTIN",	/* 21 */
 	"SIGTTOU",	/* 22 */
 };
+# define COMPAT_NSIGLIST (int)(sizeof(sys_siglist) / sizeof(sys_siglist[0]))
 #else
+# ifndef NSIG
+#  define NSIG 32
+# endif
+# define COMPAT_NSIGLIST NSIG
 extern const char *const sys_siglist[];
 #endif
 
@@ -63,7 +68,7 @@ strsignal(int s)
 {
 	static char buf[100];
 
-	if (s > 0 && s < (int)(sizeof(sys_siglist) / sizeof(sys_siglist[0])))
+	if (s > 0 && s < COMPAT_NSIGLIST)
 		return sys_siglist[s];
 
 	sprintf(buf, _("Unknown signal %d"), s);