1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
|
/*------------------------------------------------------------------
* test_strisascii_s
* File 'extstr/strisascii_s.c'
* Lines executed:100.00% of 8
*
*------------------------------------------------------------------
*/
#include "test_private.h"
#include "safe_str_lib.h"
#define LEN (128)
int main(void) {
bool rc;
uint32_t len;
char str[LEN];
int errs = 0;
/*--------------------------------------------------*/
len = 5;
#ifndef HAVE_CT_BOS_OVR
EXPECT_BOS("empty dest")
rc = strisascii_s(NULL, len);
ERR(false)
len = 0;
EXPECT_BOS("empty dest or dmax")
rc = strisascii_s("test", 0);
ERR(false)
EXPECT_BOS("dest overflow")
rc = strisascii_s(str, RSIZE_MAX_STR + 1);
ERR(false)
#ifdef HAVE___BUILTIN_OBJECT_SIZE
EXPECT_BOS("dest overflow")
rc = strisascii_s(str, LEN + 1);
ERR(false)
/* literal strings once fixed via const decl. fragile */
EXPECT_BOS("dest overflow")
rc = strisascii_s("test", RSIZE_MAX_STR + 1);
ERR(false)
EXPECT_BOS("dest overflow")
rc = strisascii_s("", 2);
ERR(false)
#endif
#endif
/*--------------------------------------------------*/
strcpy(str, "ABCDEFGHIJK");
rc = strisascii_s(str, 2);
ERR(true)
/*--------------------------------------------------*/
strcpy(str, "N");
len = strlen(str);
rc = strisascii_s(str, 1);
ERR(true)
/*--------------------------------------------------*/
strcpy(str, "N");
len = strlen(str);
rc = strisascii_s(str, 2);
ERR(true)
/*--------------------------------------------------*/
strcpy(str, "NowISTHETimE");
len = strlen(str);
rc = strisascii_s(str, len);
ERR(true)
/*--------------------------------------------------*/
strcpy(str, "qq21ego");
rc = strisascii_s(str, 33);
ERR(true)
/*--------------------------------------------------*/
strcpy(str, "1234");
str[2] = -124; /* special char: 132 */
len = strlen(str);
/* special char embedded */
rc = strisascii_s(str, len);
ERR(false)
/*--------------------------------------------------*/
return (errs);
}
|