Fix mixed measurements, begin big file edge case tests

This commit is contained in:
Victor Fernandes 2017-02-02 12:28:13 -05:00
parent 5b1abfc541
commit d8e06cc491
3 changed files with 8 additions and 6 deletions

View File

@ -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 */

View File

@ -14,7 +14,7 @@
/* standard header files */
#include <stdio.h> /* standard input/output */
#include <mm_malloc.h> /* for dynamic memory allocation. NOTE: USE MALLOC.H FOR LINUX/WINDOWS.THIS IS FOR MACOS ONLY*/
#include <malloc.h> /* for dynamic memory allocation. NOTE: USE MALLOC.H FOR LINUX/WINDOWS.THIS IS FOR MACOS ONLY*/
#include <limits.h> /* implementation-defined data type ranges and limits */
/* constant definitions */

View File

@ -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