Skip to content

Commit 6d78f9d

Browse files
committed
Fix gcc warnings about comparing signed and unsigned values
warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
1 parent d727792 commit 6d78f9d

File tree

6 files changed

+12
-11
lines changed

6 files changed

+12
-11
lines changed

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
else:
1919
kernel41 = None
2020

21-
CFLAGS = ['-Wall', '-Werror', '-Wextra', '-Wno-missing-field-initializers', '-Wno-sign-compare']
21+
CFLAGS = ['-Wall', '-Werror', '-Wextra', '-Wno-missing-field-initializers' ]
2222

2323
classifiers = ['Development Status :: 3 - Alpha',
2424
'Operating System :: POSIX :: Linux',

source/c_pwm.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,7 @@ BBIO_err pwm_start(const char *key, float duty, float freq, int polarity)
489489
{
490490
BBIO_err err;
491491
char buffer[20];
492-
int len;
492+
ssize_t len;
493493

494494
struct pwm_exp *pwm = lookup_exported_pwm(key);
495495
if (pwm == NULL) {
@@ -518,7 +518,7 @@ BBIO_err pwm_start(const char *key, float duty, float freq, int polarity)
518518
len = read(pwm->period_fd, buffer, sizeof(buffer));
519519
if (len < 0) {
520520
return BBIO_SYSFS;
521-
} else if (len >= sizeof(buffer)) {
521+
} else if (len >= (ssize_t)sizeof(buffer)) {
522522
// If this is the case, there's more in the file.
523523
// This should never happen, as it would mean that
524524
// the period is 10^8 seconds
@@ -534,7 +534,7 @@ BBIO_err pwm_start(const char *key, float duty, float freq, int polarity)
534534
len = read(pwm->duty_fd, buffer, sizeof(buffer));
535535
if (len < 0) {
536536
return BBIO_SYSFS;
537-
} else if (len >= sizeof(buffer)) {
537+
} else if (len >= (ssize_t)sizeof(buffer)) {
538538
// If this is the case, there's more in the file.
539539
// This should never happen, as it would mean that
540540
// the period is 10^8 seconds

source/common.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ BBIO_err get_pwm_key(const char *input, char *key)
339339

340340
// TODO: fix warning
341341
// source/common.c:344:14: error: comparison between signed and unsigned integer expressions [-Werror=sign-compare]
342-
BBIO_err get_adc_ain(const char *key, unsigned int *ain)
342+
BBIO_err get_adc_ain(const char *key, int *ain)
343343
{
344344
*ain = lookup_ain_by_key(key);
345345

source/common.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ int gpio_direction[120];
7979

8080
BBIO_err get_gpio_number(const char *key, unsigned int *gpio);
8181
BBIO_err get_pwm_key(const char *input, char *key);
82-
BBIO_err get_adc_ain(const char *key, unsigned int *ain);
82+
BBIO_err get_adc_ain(const char *key, int *ain);
8383
BBIO_err get_uart_device_tree_name(const char *name, char *dt);
8484
BBIO_err build_path(const char *partial_path, const char *prefix, char *full_path, size_t full_path_len);
8585
int get_spi_bus_path_number(unsigned int spi);

source/py_adc.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ static PyObject *py_setup_adc(__attribute__ ((unused)) PyObject *self, __attribu
5757
// python function read(channel)
5858
static PyObject *py_read(__attribute__ ((unused)) PyObject *self, PyObject *args)
5959
{
60-
unsigned int ain;
60+
int ain;
6161
float value;
6262
char *channel;
6363
PyObject *py_value;
@@ -100,7 +100,7 @@ static PyObject *py_read(__attribute__ ((unused)) PyObject *self, PyObject *args
100100
// python function read(channel)
101101
static PyObject *py_read_raw(__attribute__ ((unused)) PyObject *self, PyObject *args)
102102
{
103-
unsigned int ain;
103+
int ain;
104104
float value;
105105
char *channel;
106106
PyObject *py_value;

source/spimodule.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,8 @@ static PyObject *
169169
SPI_readbytes(SPI *self, PyObject *args)
170170
{
171171
uint8_t rxbuf[MAXMSGLEN];
172-
int status, len, ii;
172+
ssize_t len;
173+
int status, ii;
173174
PyObject *list;
174175

175176
if (!PyArg_ParseTuple(args, "i:read", &len))
@@ -178,7 +179,7 @@ SPI_readbytes(SPI *self, PyObject *args)
178179
/* read at least 1 byte, no more than 1024 */
179180
if (len < 1)
180181
len = 1;
181-
else if (len > sizeof(rxbuf))
182+
else if (len > (ssize_t)sizeof(rxbuf))
182183
len = sizeof(rxbuf);
183184

184185
memset(rxbuf, 0, sizeof rxbuf);
@@ -716,7 +717,7 @@ SPI_open(SPI *self, PyObject *args, PyObject *kwds)
716717
"Bus and/or device number is invalid.");
717718
return NULL;
718719
}
719-
if (load_device_tree(device_tree_name) == -1) {
720+
if (load_device_tree(device_tree_name) == BBIO_CAPE) {
720721
PyErr_SetFromErrno(PyExc_IOError);
721722
return NULL;
722723
}

0 commit comments

Comments
 (0)