Bug #57419 innobase icc warning "transfer of control bypasses initialization" in row0merge
Submitted: 13 Oct 2010 5:53 Modified: 12 May 2014 7:47
Reporter: Stewart Smith Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: InnoDB Plugin storage engine Severity:S3 (Non-critical)
Version:1.0.6+ OS:Any
Assigned to: Vasil Dimov CPU Architecture:Any
Tags: Contribution

[13 Oct 2010 5:53] Stewart Smith
Description:
If you build innodb_plugin 1.0.6 or above with ICC and warnings turned on, you can get:

plugin/innobase/row/row0merge.c(1207): error #589: transfer of control bypasses initialization of:
            variable "buf" (declared at line 1263)
            variable "file" (declared at line 1264)
            variable "index" (declared at line 1265)
  				goto err_exit;
  				^

(I verified this with a Drizzle tree, but visually inspected mysql-trunk innobase code and it's the same).

How to repeat:
build with ICC and warnings.

Suggested fix:
(will also attach patch)

fairly easy, make the code a bit more obvious about where errors are set (explicitly use error_key_num and not i)

=== modified file 'storage/innobase/row/row0merge.c'
--- storage/innobase/row/row0merge.c	2010-07-29 12:33:56 +0000
+++ storage/innobase/row/row0merge.c	2010-10-13 05:49:46 +0000
@@ -1230,9 +1230,9 @@ row_merge_read_clustered_index(
 
 		if (btr_pcur_is_after_last_on_page(&pcur)) {
 			if (UNIV_UNLIKELY(trx_is_interrupted(trx))) {
-				i = 0;
 				err = DB_INTERRUPTED;
-				goto err_exit;
+				trx->error_key_num = 0;
+				goto func_exit;
 			}
 
 			btr_pcur_store_position(&pcur, &mtr);
@@ -1274,8 +1274,8 @@ row_merge_read_clustered_index(
 
 					if (dfield_is_null(field)) {
 						err = DB_PRIMARY_KEY_IS_NULL;
-						i = 0;
-						goto err_exit;
+						trx->error_key_num = 0;
+						goto func_exit;
 					}
 
 					field_type->prtype |= DATA_NOT_NULL;
@@ -1315,7 +1315,6 @@ row_merge_read_clustered_index(
 
 					if (dup.n_dup) {
 						err = DB_DUPLICATE_KEY;
-err_exit:
 						trx->error_key_num = i;
 						goto func_exit;
 					}
@@ -1329,7 +1328,8 @@ err_exit:
 			if (!row_merge_write(file->fd, file->offset++,
 					     block)) {
 				err = DB_OUT_OF_FILE_SPACE;
-				goto err_exit;
+				trx->error_key_num = i;
+				goto func_exit;
 			}
 
 			UNIV_MEM_INVALID(block[0], sizeof block[0]);
[13 Oct 2010 5:54] Stewart Smith
fix for ICC compiler warning

Attachment: innobase_icc_transfer_of_control_row0merge.patch (text/x-patch), 1.94 KiB.

[22 May 2011 16:52] Valeriy Kravchuk
Verified by code review of current mysql-5.1 from bzr.
[22 Dec 2013 23:58] Stewart Smith
Is there any chance of this patch being incorporated? It may be rather out of date now too...
[12 May 2014 7:47] Marko Mäkelä
Posted by developer:
 
This bug was independently fixed in MySQL 5.6:

revno: 3394.2.1
revision-id: sunny.bains@oracle.com-20110821052139-anikj18tlnw02m3g
parent: marc.alff@oracle.com-20110820012311-gdkpge07sjx55cue
committer: Sunny Bains <Sunny.Bains@Oracle.Com>
branch nick: mysql-trunk-innodb-c++
timestamp: Sun 2011-08-21 15:21:39 +1000
message:
  Code changes to compile with C++.