diff --git a/buffer.c b/buffer.c index bd11fd2..8b666c8 100644 --- a/buffer.c +++ b/buffer.c @@ -73,7 +73,7 @@ Buffer* b_create(short init_capacity, char inc_factor, char o_mode) { free(pBD); return NULL; } - + pBD->addc_offset = OFFSET_RESET; pBD->capacity = init_capacity; /* END CONFIGURING BUFFER */ return pBD; @@ -165,7 +165,7 @@ int b_mode(Buffer* const pBD) { */ size_t b_incfactor(Buffer* const pBD) { if (!pBD) { return ERR_INC_FACTOR; } - return (size_t) pBD->inc_factor; + return (size_t)(unsigned char) pBD->inc_factor; } /* Reports the current position of the mark offset in the character buffer @@ -283,7 +283,7 @@ pBuffer b_addc(pBuffer const pBD, char symbol) { return NULL; } else if (pBD->mode == ADD_OP_MODE) { /* Calculate new size for additive mode */ - new_cap = pBD->capacity + pBD->inc_factor; + new_cap = pBD->capacity + (unsigned char) pBD->inc_factor; /* Make sure no short overflow happened */ if (new_cap < MIN_CAPACITY){ return NULL; @@ -295,8 +295,10 @@ pBuffer b_addc(pBuffer const pBD, char symbol) { return NULL; } + /* msvc warns about possible loss of data when converting from double to short, this is fine + because the buffer doesn't deal with floating points*/ avail_space = SHRT_MAX - pBD->capacity; - new_inc = avail_space * ((double) pBD->inc_factor) / 100; + new_inc = (short) (avail_space * (((double) pBD->inc_factor) / 100)); /* Check if there is enough space for the new increment and "trim" it if needed */ diff --git a/buffer.h b/buffer.h index 5720fcd..d084fd5 100755 --- a/buffer.h +++ b/buffer.h @@ -14,7 +14,7 @@ /* standard header files */ #include /* standard input/output */ -#include /* for dynamic memory allocation. NOTE: USE MALLOC.H FOR LINUX/WINDOWS.THIS IS FOR MACOS ONLY*/ +#include /* for dynamic memory allocation. NOTE: USE MALLOC.H FOR LINUX/WINDOWS.THIS IS FOR MACOS ONLY*/ #include /* implementation-defined data type ranges and limits */ /* constant definitions */ diff --git a/platy_bt.c b/platy_bt.c index ecc1d60..ce2edd0 100755 --- a/platy_bt.c +++ b/platy_bt.c @@ -21,7 +21,7 @@ /* constant definitions */ #define INIT_CAPACITY 200 /* initial buffer capacity */ -#define INC_FACTOR 15 /* increment factor */ +#define INC_FACTOR 15 /* increment factor */ /*check for ANSI C compliancy */ #define ANSI_C 0