Skip to content

Commit

Permalink
Fix warnings about implicit cast
Browse files Browse the repository at this point in the history
Added a few explicit casts to sds.h:

unsigned char flags = (unsigned char)s[-1];

Signed-off-by: Ted Lyngmo <[email protected]>
  • Loading branch information
TedLyngmo committed May 3, 2022
1 parent 47c3ece commit 249092a
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions sds.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ typedef long long ssize_t;
#endif

#include <sys/types.h>

#include <stdarg.h>
#include <stdint.h>

Expand Down Expand Up @@ -89,7 +90,7 @@ struct __attribute__ ((__packed__)) sdshdr64 {
#define SDS_TYPE_5_LEN(f) ((f)>>SDS_TYPE_BITS)

static inline size_t sdslen(const sds s) {
unsigned char flags = s[-1];
unsigned char flags = (unsigned char)s[-1];
switch(flags&SDS_TYPE_MASK) {
case SDS_TYPE_5:
return SDS_TYPE_5_LEN(flags);
Expand All @@ -106,7 +107,7 @@ static inline size_t sdslen(const sds s) {
}

static inline size_t sdsavail(const sds s) {
unsigned char flags = s[-1];
unsigned char flags = (unsigned char)s[-1];
switch(flags&SDS_TYPE_MASK) {
case SDS_TYPE_5: {
return 0;
Expand All @@ -132,7 +133,7 @@ static inline size_t sdsavail(const sds s) {
}

static inline void sdssetlen(sds s, size_t newlen) {
unsigned char flags = s[-1];
unsigned char flags = (unsigned char)s[-1];
switch(flags&SDS_TYPE_MASK) {
case SDS_TYPE_5:
{
Expand All @@ -156,7 +157,7 @@ static inline void sdssetlen(sds s, size_t newlen) {
}

static inline void sdsinclen(sds s, size_t inc) {
unsigned char flags = s[-1];
unsigned char flags = (unsigned char)s[-1];
switch(flags&SDS_TYPE_MASK) {
case SDS_TYPE_5:
{
Expand All @@ -182,7 +183,7 @@ static inline void sdsinclen(sds s, size_t inc) {

/* sdsalloc() = sdsavail() + sdslen() */
static inline size_t sdsalloc(const sds s) {
unsigned char flags = s[-1];
unsigned char flags = (unsigned char)s[-1];
switch(flags&SDS_TYPE_MASK) {
case SDS_TYPE_5:
return SDS_TYPE_5_LEN(flags);
Expand All @@ -199,7 +200,7 @@ static inline size_t sdsalloc(const sds s) {
}

static inline void sdssetalloc(sds s, size_t newlen) {
unsigned char flags = s[-1];
unsigned char flags = (unsigned char)s[-1];
switch(flags&SDS_TYPE_MASK) {
case SDS_TYPE_5:
/* Nothing to do, this type has no total allocation info. */
Expand Down

0 comments on commit 249092a

Please sign in to comment.