fix MSVC warnings

This commit is contained in:
Enno Rehling 2022-02-22 19:23:08 +01:00
parent 0fe17b4c0f
commit dd1efa973d
4 changed files with 27 additions and 25 deletions

View File

@ -9,10 +9,5 @@ target_link_libraries (CuTestTest cutest)
enable_testing()
add_test (cutest CuTestTest)
IF (MSVC)
find_package (MSVC MODULE)
MSVC_CRT_SECURE_NO_WARNINGS (${PROJECT_NAME} CuTestTest)
ENDIF (MSVC)
set (CUTEST_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR} CACHE INTERNAL "CuTest headers")
set (CUTEST_LIBRARIES cutest CACHE INTERNAL "CuTest libraries")

View File

@ -1,3 +1,6 @@
#ifdef _MSC_VER
#define _CRT_SECURE_NO_WARNINGS
#endif
#include <assert.h>
#include <setjmp.h>
#include <stdlib.h>
@ -11,7 +14,7 @@
* CuStr
*-------------------------------------------------------------------------*/
char* CuStrAlloc(int size)
char* CuStrAlloc(size_t size)
{
char* newStr = (char*) malloc( sizeof(char) * (size) );
return newStr;
@ -19,7 +22,7 @@ char* CuStrAlloc(int size)
char* CuStrCopy(const char* old)
{
int len = strlen(old);
size_t len = strlen(old);
char* newStr = CuStrAlloc(len + 1);
strcpy(newStr, old);
return newStr;
@ -54,7 +57,7 @@ void CuStringDelete(CuString *str)
free(str);
}
void CuStringResize(CuString* str, int newSize)
void CuStringResize(CuString* str, size_t newSize)
{
str->buffer = (char*) realloc(str->buffer, sizeof(char) * newSize);
str->size = newSize;
@ -62,7 +65,7 @@ void CuStringResize(CuString* str, int newSize)
void CuStringAppend(CuString* str, const char* text)
{
int length;
size_t length;
if (text == NULL) {
text = "NULL";
@ -93,9 +96,9 @@ void CuStringAppendFormat(CuString* str, const char* format, ...)
CuStringAppend(str, buf);
}
void CuStringInsert(CuString* str, const char* text, int pos)
void CuStringInsert(CuString* str, const char* text, size_t pos)
{
int length = strlen(text);
size_t length = strlen(text);
if (pos > str->length)
pos = str->length;
if (str->length + length + 1 >= str->size)

View File

@ -3,12 +3,13 @@
#include <setjmp.h>
#include <stdarg.h>
#include <stddef.h>
#define CUTEST_VERSION "CuTest 1.5b"
#define CUTEST_VERSION "CuTest 1.5c"
/* CuString */
char* CuStrAlloc(int size);
char* CuStrAlloc(size_t size);
char* CuStrCopy(const char* old);
#define CU_ALLOC(TYPE) ((TYPE*) malloc(sizeof(TYPE)))
@ -19,8 +20,8 @@ char* CuStrCopy(const char* old);
typedef struct
{
int length;
int size;
size_t length;
size_t size;
char* buffer;
} CuString;
@ -30,8 +31,8 @@ void CuStringRead(CuString* str, const char* path);
void CuStringAppend(CuString* str, const char* text);
void CuStringAppendChar(CuString* str, char ch);
void CuStringAppendFormat(CuString* str, const char* format, ...);
void CuStringInsert(CuString* str, const char* text, int pos);
void CuStringResize(CuString* str, int newSize);
void CuStringInsert(CuString* str, const char* text, size_t pos);
void CuStringResize(CuString* str, size_t newSize);
void CuStringDelete(CuString* str);
/* CuTest */

View File

@ -1,3 +1,6 @@
#ifdef _MSC_VER
#define _CRT_SECURE_NO_WARNINGS
#endif
#include <assert.h>
#include <setjmp.h>
#include <stdlib.h>
@ -55,10 +58,10 @@ void TestCuStringAppend(CuTest* tc)
{
CuString* str = CuStringNew();
CuStringAppend(str, "hello");
CuAssertIntEquals(tc, 5, str->length);
CuAssertIntEquals(tc, 5, (int)str->length);
CuAssertStrEquals(tc, "hello", str->buffer);
CuStringAppend(str, " world");
CuAssertIntEquals(tc, 11, str->length);
CuAssertIntEquals(tc, 11, (int)str->length);
CuAssertStrEquals(tc, "hello world", str->buffer);
}
@ -67,7 +70,7 @@ void TestCuStringAppendNULL(CuTest* tc)
{
CuString* str = CuStringNew();
CuStringAppend(str, NULL);
CuAssertIntEquals(tc, 4, str->length);
CuAssertIntEquals(tc, 4, (int)str->length);
CuAssertStrEquals(tc, "NULL", str->buffer);
}
@ -79,7 +82,7 @@ void TestCuStringAppendChar(CuTest* tc)
CuStringAppendChar(str, 'b');
CuStringAppendChar(str, 'c');
CuStringAppendChar(str, 'd');
CuAssertIntEquals(tc, 4, str->length);
CuAssertIntEquals(tc, 4, (int)str->length);
CuAssertStrEquals(tc, "abcd", str->buffer);
}
@ -88,16 +91,16 @@ void TestCuStringInserts(CuTest* tc)
{
CuString* str = CuStringNew();
CuStringAppend(str, "world");
CuAssertIntEquals(tc, 5, str->length);
CuAssertIntEquals(tc, 5, (int)str->length);
CuAssertStrEquals(tc, "world", str->buffer);
CuStringInsert(str, "hell", 0);
CuAssertIntEquals(tc, 9, str->length);
CuAssertIntEquals(tc, 9, (int)str->length);
CuAssertStrEquals(tc, "hellworld", str->buffer);
CuStringInsert(str, "o ", 4);
CuAssertIntEquals(tc, 11, str->length);
CuAssertIntEquals(tc, 11, (int)str->length);
CuAssertStrEquals(tc, "hello world", str->buffer);
CuStringInsert(str, "!", 11);
CuAssertIntEquals(tc, 12, str->length);
CuAssertIntEquals(tc, 12, (int)str->length);
CuAssertStrEquals(tc, "hello world!", str->buffer);
}