Bug #8983 one place that isn't strict-aliasing-safe
Submitted: 5 Mar 2005 21:27 Modified: 15 Feb 2007 5:06
Reporter: [ name withheld ] Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server Severity:S3 (Non-critical)
Version:4.1.10 OS:Linux (Linux)
Assigned to: Magnus BlÄudd CPU Architecture:Any

[5 Mar 2005 21:27] [ name withheld ]
Description:
Dunno if you harbor any ambitions of making mysql safe to build under -f-strict-aliasing in recent gcc releases.  If you do, here is one place
that needs fixed.

How to repeat:
Without -f-nostrict-aliasing, there is a failure in the mysql_client_test regression test on (at least) x86_64 under current gcc 4.0, because the wrong value of "packet" gets passed into set_params.

Suggested fix:
diff -Naur mysql-4.1.10.orig/sql/sql_prepare.cc mysql-4.1.10/sql/sql_prepare.cc
--- mysql-4.1.10.orig/sql/sql_prepare.cc	2005-02-12 15:37:31.000000000 -0500
+++ mysql-4.1.10/sql/sql_prepare.cc	2005-03-05 15:42:48.000000000 -0500
@@ -1747,8 +1747,9 @@
       packet_length  Query string length, including terminator character.
 */
 
-void mysql_stmt_execute(THD *thd, char *packet, uint packet_length)
+void mysql_stmt_execute(THD *thd, char *cpacket, uint packet_length)
 {
+  uchar *packet = (uchar *) cpacket;
   ulong stmt_id= uint4korr(packet);
   /*
     Query text for binary log, or empty string if the query is not put into
@@ -1756,7 +1757,7 @@
   */
   String expanded_query;
 #ifndef EMBEDDED_LIBRARY
-  uchar *packet_end= (uchar *) packet + packet_length - 1;
+  uchar *packet_end= packet + packet_length - 1;
 #endif
   Prepared_statement *stmt;
   DBUG_ENTER("mysql_stmt_execute");
@@ -1781,9 +1782,9 @@
 #ifndef EMBEDDED_LIBRARY
   if (stmt->param_count)
   {
-    uchar *null_array= (uchar *) packet;
-    if (setup_conversion_functions(stmt, (uchar **) &packet, packet_end) ||
-        stmt->set_params(stmt, null_array, (uchar *) packet, packet_end,
+    uchar *null_array= packet;
+    if (setup_conversion_functions(stmt, &packet, packet_end) ||
+        stmt->set_params(stmt, null_array, packet, packet_end,
                          &expanded_query))
       goto set_params_data_err;
   }
[24 Mar 2005 5:23] Jorge del Conde
Thanks for your bug report
[6 Feb 2007 13:07] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/19383

ChangeSet@1.2595, 2007-02-06 14:07:40+01:00, msvensson@neptunus.(none) +1 -0
  Bug#8983 one place that isn't strict-aliasing-safe
   - Backport fix from 5.0
[14 Feb 2007 14:56] Chad MILLER
Available in 4.1.23, 5.0.36, and 5.1.16-beta.
[15 Feb 2007 5:06] Paul DuBois
No changelog entry needed.