Quellcode durchsuchen

libdpkg, dpkg-deb: Fix compound literal usage with C99 compilers

We cannot portably assign a compound literal to a static variable,
as the expression is not constant. GCC accepts these for backwards
compatibility in its C89 mode, but not in its C99 mode.
Guillem Jover vor 12 Jahren
Ursprung
Commit
07413972ae
4 geänderte Dateien mit 20 neuen und 6 gelöschten Zeilen
  1. 2 0
      debian/changelog
  2. 2 2
      dpkg-deb/main.c
  3. 8 2
      lib/dpkg/deb-version.h
  4. 8 2
      lib/dpkg/pkg-queue.h

+ 2 - 0
debian/changelog

@@ -72,6 +72,8 @@ dpkg (1.17.7) UNRELEASED; urgency=low
     This will allow non-GNU systems to easily use another value for their
     GNU tar, which is usually either gnutar or gtar.
   * Require compound literals support in the compiler at configure time.
+  * Fix compound literals usage with compilers in C99 mode, by not assigning
+    them to static variables.
 
   [ Updated dpkg translations ]
   * German (Sven Joachim).

+ 2 - 2
dpkg-deb/main.c

@@ -166,7 +166,7 @@ set_deb_format(const struct cmdinfo *cip, const char *value)
 static void
 set_deb_old(const struct cmdinfo *cip, const char *value)
 {
-  deb_format = DEB_VERSION(0, 939000);
+  deb_format = DEB_VERSION_OBJECT(0, 939000);
 
   warning(_("obsolete option '--%s'; please use '--%s' instead"),
           cip->olong, "deb-format=0.939000");
@@ -175,7 +175,7 @@ set_deb_old(const struct cmdinfo *cip, const char *value)
 static void
 set_deb_new(const struct cmdinfo *cip, const char *value)
 {
-  deb_format = DEB_VERSION(2, 0);
+  deb_format = DEB_VERSION_OBJECT(2, 0);
 
   warning(_("obsolete option '--%s'; please use '--%s' instead"),
           cip->olong, "deb-format=2.0");

+ 8 - 2
lib/dpkg/deb-version.h

@@ -40,10 +40,16 @@ struct deb_version {
 };
 
 /**
- * Initializer for a deb_version.
+ * Constant initializer for a deb_version.
  */
 #define DEB_VERSION(X, Y) \
-	(struct deb_version){ .major = (X), .minor = (Y) }
+	{ .major = (X), .minor = (Y) }
+
+/**
+ * Compound literal for a deb_version.
+ */
+#define DEB_VERSION_OBJECT(X, Y) \
+	(struct deb_version)DEB_VERSION(X, Y)
 
 const char *deb_version_parse(struct deb_version *version, const char *str);
 

+ 8 - 2
lib/dpkg/pkg-queue.h

@@ -38,10 +38,16 @@ struct pkg_queue {
 };
 
 /**
- * Initializer for a package queue.
+ * Constant initializer for a package queue.
  */
 #define PKG_QUEUE_INIT \
-	(struct pkg_queue){ .head = NULL, .tail = NULL, .length = 0 }
+	{ .head = NULL, .tail = NULL, .length = 0 }
+
+/**
+ * Compound literal for a package queue.
+ */
+#define PKG_QUEUE_OBJECT \
+	(struct pkg_queue)PKG_QUEUE_INIT
 
 void pkg_queue_init(struct pkg_queue *queue);
 void pkg_queue_destroy(struct pkg_queue *queue);