Skip to content

Commit b3c6ea7

Browse files
committed
Tightened compiler warnings, fixed -Wconversion errors.
1 parent eab2d5d commit b3c6ea7

File tree

3 files changed

+14
-9
lines changed

3 files changed

+14
-9
lines changed

Diff for: CMakeLists.txt

+2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
1717

1818
INCLUDE_DIRECTORIES(".")
1919

20+
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Werror -Wconversion")
21+
2022
SET(WSREP_SOURCES wsrep_gtid.c wsrep_uuid.c wsrep_loader.c wsrep_dummy.c)
2123

2224
ADD_LIBRARY(wsrep ${WSREP_SOURCES})

Diff for: wsrep_gtid.c

+11-8
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include <stdio.h>
2121
#include <stdlib.h>
2222
#include <inttypes.h>
23+
#include <limits.h>
2324

2425
#include "wsrep_api.h"
2526

@@ -30,20 +31,20 @@
3031
int
3132
wsrep_gtid_scan(const char* str, size_t str_len, wsrep_gtid_t* gtid)
3233
{
33-
unsigned int offset;
34+
int offset;
3435
char* endptr;
36+
if (str_len > INT_MAX) return -EINVAL;
3537

3638
if ((offset = wsrep_uuid_scan(str, str_len, &gtid->uuid)) > 0 &&
37-
offset < str_len && str[offset] == ':') {
39+
offset < (int)str_len && str[offset] == ':') {
3840
++offset;
39-
if (offset < str_len)
41+
if (offset < (int)str_len)
4042
{
4143
errno = 0;
4244
gtid->seqno = strtoll(str + offset, &endptr, 0);
4345

4446
if (errno == 0) {
45-
offset = endptr - str;
46-
return offset;
47+
return (int)(endptr - str);
4748
}
4849
}
4950
}
@@ -59,12 +60,14 @@ wsrep_gtid_scan(const char* str, size_t str_len, wsrep_gtid_t* gtid)
5960
int
6061
wsrep_gtid_print(const wsrep_gtid_t* gtid, char* str, size_t str_len)
6162
{
62-
unsigned int offset, ret;
63+
int offset, ret;
64+
if (str_len > INT_MAX) return -EINVAL;
65+
6366
if ((offset = wsrep_uuid_print(&gtid->uuid, str, str_len)) > 0)
6467
{
65-
ret = snprintf(str + offset, str_len - offset,
68+
ret = snprintf(str + offset, (size_t)((int)str_len - offset),
6669
":%" PRId64, gtid->seqno);
67-
if (ret <= str_len - offset) {
70+
if (ret <= ((int)str_len - offset)) {
6871
return (offset + ret);
6972
}
7073

Diff for: wsrep_uuid.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ wsrep_uuid_scan (const char* str, size_t str_len, wsrep_uuid_t* uuid)
5151
uuid_len += 2;
5252
uuid_offt += 1;
5353
if (sizeof (uuid->data) == uuid_offt)
54-
return uuid_len;
54+
return (int)uuid_len;
5555
}
5656
else {
5757
break;

0 commit comments

Comments
 (0)