Bug #76913 suspicious code in str_to_datetime

Submitted: 2 May 2015 11:13 Modified: 8 Jun 2015 10:34
Reporter: Shane Bester (Platinum Quality Contributor) Email Updates:
Status: Verified Impact on me:
None 
Category:MySQL Server: Data Types Severity:S3 (Non-critical)
Version:5.5, 5.6, 5.7, 8.0 OS:Any
Assigned to: CPU Architecture:Any

[2 May 2015 11:13] Shane Bester
Description:
In the function str_to_datetime in .\sql-common\my_time.c we have this fragment of code that looks strange:

        if (str+2 <= end && (str[1] == 'M' || str[1] == 'm'))
        {
          if (str[0] == 'p' || str[0] == 'P')
            add_hours= 12;
 ----->   else if (str[0] != 'a' || str[0] != 'A')   <-------------
            continue;                           /* Not AM/PM */
          str+= 2;                              /* Skip AM/PM */
          /* Skip space after AM/PM */

How to repeat:
Read the code.
Sorry, I can't get a testcase to do coverage of this part code...

Suggested fix:
- else if (str[0] != 'a' || str[0] != 'A')
+ else if (str[0] != 'a' && str[0] != 'A')
[2 May 2015 11:53] Shane Bester
in 5.0, 5.1 it looks okay.  since 5.5.0, this bug exists.
[8 Jun 2015 10:34] Shane Bester
verifying as the code is obviously wrong but i cannot get a sql testcase to hit this line ;)

Portions of this website are copyright © 2001, 2002 The PHP Group

Page generated in 0.052 sec. using MySQL 8.4.7-u6-cloud

Timestamp references displayed by the system are UTC.
Content reproduced on this site is the property of the respective copyright holders.
It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.