Skip to content

Commit 47f80ff

Browse files
committed
Remove unnecessary type punnign from mysqli_api.c
value is a long. On big-endian architectures mysql_stmt_attr_get() will write to the most significant byte. Type punning was used to move that byte to the least significant one, which is UB. We can avoid this by simply casting to my_bool (alias of bool). Previously, a comparison against 0 should've been done.
1 parent f60dc47 commit 47f80ff

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

ext/mysqli/mysqli_api.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -1799,11 +1799,11 @@ PHP_FUNCTION(mysqli_stmt_attr_get)
17991799
"MYSQLI_STMT_ATTR_UPDATE_MAX_LENGTH, "
18001800
"MYSQLI_STMT_ATTR_PREFETCH_ROWS, or STMT_ATTR_CURSOR_TYPE");
18011801
RETURN_THROWS();
1802-
}
1803-
1802+
}
18041803

18051804
if (attr == STMT_ATTR_UPDATE_MAX_LENGTH)
1806-
value = *((my_bool *)&value);
1805+
value = (my_bool)value;
1806+
18071807
RETURN_LONG((unsigned long)value);
18081808
}
18091809
/* }}} */

0 commit comments

Comments
 (0)