20
20
#include <stdio.h>
21
21
#include <stdlib.h>
22
22
#include <inttypes.h>
23
+ #include <limits.h>
23
24
24
25
#include "wsrep_api.h"
25
26
30
31
int
31
32
wsrep_gtid_scan (const char * str , size_t str_len , wsrep_gtid_t * gtid )
32
33
{
33
- unsigned int offset ;
34
+ int offset ;
34
35
char * endptr ;
36
+ if (str_len > INT_MAX ) return - EINVAL ;
35
37
36
38
if ((offset = wsrep_uuid_scan (str , str_len , & gtid -> uuid )) > 0 &&
37
- offset < str_len && str [offset ] == ':' ) {
39
+ offset < ( int ) str_len && str [offset ] == ':' ) {
38
40
++ offset ;
39
- if (offset < str_len )
41
+ if (offset < ( int ) str_len )
40
42
{
41
43
errno = 0 ;
42
44
gtid -> seqno = strtoll (str + offset , & endptr , 0 );
43
45
44
46
if (errno == 0 ) {
45
- offset = endptr - str ;
46
- return offset ;
47
+ return (int )(endptr - str );
47
48
}
48
49
}
49
50
}
@@ -59,12 +60,14 @@ wsrep_gtid_scan(const char* str, size_t str_len, wsrep_gtid_t* gtid)
59
60
int
60
61
wsrep_gtid_print (const wsrep_gtid_t * gtid , char * str , size_t str_len )
61
62
{
62
- unsigned int offset , ret ;
63
+ int offset , ret ;
64
+ if (str_len > INT_MAX ) return - EINVAL ;
65
+
63
66
if ((offset = wsrep_uuid_print (& gtid -> uuid , str , str_len )) > 0 )
64
67
{
65
- ret = snprintf (str + offset , str_len - offset ,
68
+ ret = snprintf (str + offset , ( size_t )(( int ) str_len - offset ) ,
66
69
":%" PRId64 , gtid -> seqno );
67
- if (ret <= str_len - offset ) {
70
+ if (ret <= (( int ) str_len - offset ) ) {
68
71
return (offset + ret );
69
72
}
70
73
0 commit comments