Skip to content

Commit 766ff57

Browse files
author
Joao Gramacho
committed
Bug#16997513 MY_STRTOLL10 ACCEPTING OVERFLOWED UNSIGNED LONG LONG VALUES AS NORMAL ONES
Merge from mysql-5.5 into mysql-5.6
2 parents d026e54 + bec8595 commit 766ff57

3 files changed

Lines changed: 50 additions & 2 deletions

File tree

strings/my_strtoll10.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,8 @@ longlong my_strtoll10(const char *nptr, char **endptr, int *error)
193193
goto overflow;
194194

195195
/* Check that we didn't get an overflow with the last digit */
196-
if (i > cutoff || (i == cutoff && ((j > cutoff2 || j == cutoff2) &&
197-
k > cutoff3)))
196+
if (i > cutoff || (i == cutoff && (j > cutoff2 || (j == cutoff2 &&
197+
k > cutoff3))))
198198
goto overflow;
199199
li=i*LFACTOR2+ (ulonglong) j*100 + k;
200200
return (longlong) li;

unittest/gunit/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,7 @@ SET(TESTS
244244
sql_plist
245245
sql_string
246246
stdcxx
247+
strtoll
247248
thread_utils
248249
)
249250

unittest/gunit/strtoll-t.cc

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
2+
3+
This program is free software; you can redistribute it and/or modify
4+
it under the terms of the GNU General Public License as published by
5+
the Free Software Foundation; version 2 of the License.
6+
7+
This program is distributed in the hope that it will be useful,
8+
but WITHOUT ANY WARRANTY; without even the implied warranty of
9+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10+
GNU General Public License for more details.
11+
12+
You should have received a copy of the GNU General Public License
13+
along with this program; if not, write to the Free Software
14+
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
15+
16+
// First include (the generated) my_config.h, to get correct platform defines.
17+
#include "my_config.h"
18+
#include <gtest/gtest.h>
19+
/*
20+
21+
==== Purpose ====
22+
23+
Test if my_strtoll10 overflows values above unsigned long long
24+
limit correctly.
25+
26+
==== Related Bugs and Worklogs ====
27+
28+
BUG#16997513: MY_STRTOLL10 ACCEPTING OVERFLOWED UNSIGNED LONG LONG
29+
VALUES AS NORMAL ONES
30+
31+
==== Implementation ====
32+
33+
Check if my_strtoll10 returns the larger unsigned long long and raise
34+
the overflow error when receiving a number like 18446744073709551915
35+
36+
*/
37+
#include <m_string.h>
38+
39+
TEST(StringToULLTest, OverflowedNumber)
40+
{
41+
unsigned long long number;
42+
int error;
43+
const char * str= "18446744073709551915";
44+
number= my_strtoll10(str, 0, &error);
45+
EXPECT_EQ(number, ULONGLONG_MAX);
46+
EXPECT_EQ(error, MY_ERRNO_ERANGE);
47+
}

0 commit comments

Comments
 (0)