Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 255d1ad

Browse files
authored
better max_allowed_packet parsing (#1661)
Remove `stringToInt()` and use `strconv.Atoi` instead.
1 parent 7403860 commit 255d1ad

File tree

2 files changed

+7
-11
lines changed

2 files changed

+7
-11
lines changed

‎connector.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ package mysql
1111
import (
1212
"context"
1313
"database/sql/driver"
14+
"fmt"
1415
"net"
1516
"os"
1617
"strconv"
@@ -179,7 +180,12 @@ func (c *connector) Connect(ctx context.Context) (driver.Conn, error) {
179180
mc.Close()
180181
return nil, err
181182
}
182-
mc.maxAllowedPacket = stringToInt(maxap) - 1
183+
n, err := strconv.Atoi(string(maxap))
184+
if err != nil {
185+
mc.Close()
186+
return nil, fmt.Errorf("invalid max_allowed_packet value (%q): %w", maxap, err)
187+
}
188+
mc.maxAllowedPacket = n - 1
183189
}
184190
if mc.maxAllowedPacket < maxPacketSize {
185191
mc.maxWriteSize = mc.maxAllowedPacket

‎utils.go

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -524,16 +524,6 @@ func uint64ToString(n uint64) []byte {
524524
return a[i:]
525525
}
526526

527-
// treats string value as unsigned integer representation
528-
func stringToInt(b []byte) int {
529-
val := 0
530-
for i := range b {
531-
val *= 10
532-
val += int(b[i] - 0x30)
533-
}
534-
return val
535-
}
536-
537527
// returns the string read as a bytes slice, whether the value is NULL,
538528
// the number of bytes read and an error, in case the string is longer than
539529
// the input slice

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /