Skip to content

Commit

Permalink
Indicate and document unreachable code section
Browse files Browse the repository at this point in the history
Based on Sergei Golubchik's question in
mariadb-corporation#223 (comment)
  • Loading branch information
dlenski committed Dec 5, 2023
1 parent 777e956 commit 8529511
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions libmariadb/mariadb_lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
#include <time.h>
#include <mariadb_dyncol.h>
#include <mariadb_rpl.h>
#include <my_global.h>

#ifndef __has_feature
# define __has_feature(x) 0
Expand Down Expand Up @@ -1811,6 +1812,20 @@ MYSQL *mthd_my_real_connect(MYSQL *mysql, const char *host, const char *user,
/* Check if server sends an error */
if (mysql->protocol_version == 0XFF)
{
/* This code appears to be unreachable.
*
* 1. `if (mysql->protocol_version == 0XFF)` is checking the first
* byte of the packet received by `ma_net_safe_read` above.
* 2. But if the first byte of the packet body received by
* `ma_net_safe_read` had been 0xff, then `ma_net_safe_read`
* would have returned `packet_error`.
* (See its source above, in this same file.)
* 3. Therefore, we would have taken the above branch
* (`if (ma_net_safe_read(mysql) == packet_error)`), and jumped
* straight to `goto error`, skipping this section.
*/
MY_ASSERT_UNREACHABLE();

net_get_error(end, pkt_length - 1, net->last_error, sizeof(net->last_error),
&net->last_errno, net->sqlstate);
/* fix for bug #26426 */
Expand Down

0 comments on commit 8529511

Please sign in to comment.