Bug #5958: zero out padding bytes in requests.
[free-sw/xcb/libxcb] / src / c-client.xsl
index 31b6de5..0f7c025 100644 (file)
@@ -47,6 +47,8 @@ authorization from the authors.
 
   <xsl:variable name="h" select="$mode = 'header'" />
   <xsl:variable name="c" select="$mode = 'source'" />
+
+  <xsl:variable name="need-string-h" select="//request/pad[@bytes != 1]" />
   
   <!-- String used to indent lines of code. -->
   <xsl:variable name="indent-string" select="'    '" />
@@ -720,7 +722,7 @@ authorization from the authors.
     <l><xsl:value-of select="@ref" /> xcb_out;</l>
 
     <l />
-    <xsl:apply-templates select="$struct//*[(self::field or self::exprfield)
+    <xsl:apply-templates select="$struct//*[(self::field or self::exprfield or self::pad)
                                             and not(boolean(@no-assign))]"
                          mode="assign" />
 
@@ -779,6 +781,14 @@ authorization from the authors.
     </l>
   </xsl:template>
 
+  <xsl:template match="pad" mode="assign">
+    <xsl:variable name="padnum"><xsl:number /></xsl:variable>
+    <l><xsl:choose>
+        <xsl:when test="@bytes = 1">xcb_out.pad<xsl:value-of select="$padnum - 1" /> = 0;</xsl:when>
+        <xsl:otherwise>memset(xcb_out.pad<xsl:value-of select="$padnum - 1" />, 0, <xsl:value-of select="@bytes" />);</xsl:otherwise>
+    </xsl:choose></l>
+  </xsl:template>
+
   <xsl:template match="iterator" mode="pass2">
     <struct name="{@ref}_iterator_t">
       <field type="{@ref}_t *" name="data" />
@@ -973,11 +983,13 @@ authorization from the authors.
       -->__<xsl:value-of select="$ucase-header" />_H<!--
     --></xsl:variable>
 
-<xsl:text>/**
- * @file </xsl:text><xsl:value-of select="$header" /><xsl:text>.h
- **/
+<xsl:text>/*
+ * This file generated automatically from </xsl:text>
+<xsl:value-of select="$header" /><xsl:text>.xml by c-client.xsl using XSLT.
+ * Edit at your peril.
+ */
 </xsl:text>
-<xsl:text>
+<xsl:if test="$h"><xsl:text>
 /**
  * @defgroup XCB_</xsl:text><xsl:value-of select="$ext" /><xsl:text>_API XCB </xsl:text><xsl:value-of select="$ext" /><xsl:text> API
  * @brief </xsl:text><xsl:value-of select="$ext" /><xsl:text> XCB Protocol Implementation.</xsl:text>
@@ -985,14 +997,8 @@ authorization from the authors.
  * @{
  **/
 </xsl:text>
-<xsl:text>/*
- * This file generated automatically from </xsl:text>
-<xsl:value-of select="$header" /><xsl:text>.xml by c-client.xsl using XSLT.
- * Edit at your peril.
- */
-</xsl:text>
 
-<xsl:if test="$h"><xsl:text>
+<xsl:text>
 #ifndef </xsl:text><xsl:value-of select="$guard" /><xsl:text>
 #define </xsl:text><xsl:value-of select="$guard" /><xsl:text>
 </xsl:text>
@@ -1017,7 +1023,10 @@ authorization from the authors.
   </xsl:choose>
 </xsl:if>
 
-<xsl:if test="$c"><xsl:text>
+<xsl:if test="$c">
+<xsl:if test="$need-string-h">
+#include &lt;string.h&gt;</xsl:if>
+<xsl:text>
 #include &lt;assert.h&gt;
 #include "xcbext.h"
 #include "</xsl:text><xsl:value-of select="$header" /><xsl:text>.h"
@@ -1028,10 +1037,11 @@ authorization from the authors.
 
 <xsl:if test="$h">
 <xsl:text>
+#endif
+
 /**
  * @}
  */
-#endif
 </xsl:text>
 </xsl:if>
   </xsl:template>