Add casts to avoid some compiler warnings
if the compiler is not able to detect the cast if safe.
This commit is contained in:
1 parent
bf49b8e933
commit
3f84f54d65
5 files changed
+76
-8
No files matched your search
@@ -0,0 +1,68 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
/*
|
||||||
|
fscanf --> %c, %s, %[ have additional parameters (size) MS is unsigned. Std is rsize_t
|
||||||
|
fprintf --> No %n
|
||||||
|
snprintf --> No %n
|
||||||
|
vsnprintf --> No %n, MS prototype incompatible with Standard ! (additional arg) can be added automatically ?
|
||||||
|
qsort --> Nothing ?
|
||||||
|
memcpy --> Additional arg buffer alloc
|
||||||
|
memmove--> Additional arg buffer alloc
|
||||||
|
strncpy--> Additional arg buffer alloc
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* If Microsoft Visual Studio C Library
|
||||||
|
* ==> Use Annex K like functions to avoid warnings
|
||||||
|
*/
|
||||||
|
#if defined(_MSC_VER) && defined(__STDC_WANT_LIB_EXT1__) && __STDC_WANT_LIB_EXT1__
|
||||||
|
|
||||||
|
#define m_fprintf(...) fprintf_s(__VA_ARGS__)
|
||||||
|
#define m_snprintf(...) snprintf_s(__VA_ARGS__)
|
||||||
|
#define m_qsort(...) qsort_s(__VA_ARGS__)
|
||||||
|
#define m_vsnprintf(s, n, ...) vsnprintf_s(s, n, (n)-1, __VA_ARGS__)
|
||||||
|
#define m_memcpy(d, s, size) memcpy_s(d, size, s, size)
|
||||||
|
#define m_memmove(d, s, size) memmove_s(d, size, s, size)
|
||||||
|
#define m_strncpy(s1, s2, size) strncpy_s(s1, size, s2, size)
|
||||||
|
#define m_fscanf(...) fscanf_s(__VA_ARGS__)
|
||||||
|
#define m_fscanf_strarg(arg, size) arg, size
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
/* Use classic C functions */
|
||||||
|
#define m_fprintf(...) fprintf(__VA_ARGS__)
|
||||||
|
#define m_snprintf(...) snprintf(__VA_ARGS__)
|
||||||
|
#define m_qsort(...) qsort(__VA_ARGS__)
|
||||||
|
#define m_vsnprintf(...) vsnprintf(__VA_ARGS__)
|
||||||
|
#define m_memcpy(...) memcpy(__VA_ARGS__)
|
||||||
|
#define m_memmove(...) memmove(__VA_ARGS__)
|
||||||
|
#define m_fscanf(...) fscanf(__VA_ARGS__)
|
||||||
|
#define m_fscanf_strarg(arg, size) arg
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
void PrintFError ( const char * format, ... )
|
||||||
|
{
|
||||||
|
char buffer[256];
|
||||||
|
va_list args;
|
||||||
|
va_start (args, format);
|
||||||
|
m_vsnprintf (buffer,256,format, args);
|
||||||
|
m_fprintf (stderr, "%s", buffer);
|
||||||
|
va_end (args);
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(void)
|
||||||
|
{
|
||||||
|
m_fprintf(stdout, "This is a test %d!\n", 8);
|
||||||
|
char buffer[100];
|
||||||
|
m_snprintf(buffer, sizeof buffer, "%d", 18);
|
||||||
|
m_fprintf(stdout, "%s. Please enter your name:\n", buffer);
|
||||||
|
m_fscanf(stdin, " %99s", m_fscanf_strarg(buffer, sizeof buffer));
|
||||||
|
char buffer2[100];
|
||||||
|
m_memcpy(buffer2, buffer, sizeof buffer);
|
||||||
|
char buffer3[100];
|
||||||
|
m_memmove(buffer3, buffer2, sizeof buffer3);
|
||||||
|
PrintFError("There is an error, %s\n", buffer3);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
@@ -1584,7 +1584,7 @@ m_core_parse_bool (bool *ptr, const char str[], const char **endptr)
|
|||||||
name (type *ptr, const char str[], const char **endptr) \
|
name (type *ptr, const char str[], const char **endptr) \
|
||||||
{ \
|
{ \
|
||||||
char *end; \
|
char *end; \
|
||||||
*ptr = parse_func (str, &end extra_arg); \
|
*ptr = (type) parse_func (str, &end extra_arg); \
|
||||||
if (endptr != NULL) *endptr = end; \
|
if (endptr != NULL) *endptr = end; \
|
||||||
return end != str; \
|
return end != str; \
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1846,7 +1846,7 @@ typedef enum {
|
|||||||
DICTI_OA_CONTRACT(dict); \
|
DICTI_OA_CONTRACT(dict); \
|
||||||
size_t size; \
|
size_t size; \
|
||||||
/* Get the size which will allow to fit this capacity */ \
|
/* Get the size which will allow to fit this capacity */ \
|
||||||
size = m_core_roundpow2 (capacity * (1.0 / coeff_up)); \
|
size = m_core_roundpow2 ((uint64_t) (capacity * (1.0 / coeff_up))); \
|
||||||
/* Test for overflow of the computation */ \
|
/* Test for overflow of the computation */ \
|
||||||
if (M_UNLIKELY (size < capacity)) { \
|
if (M_UNLIKELY (size < capacity)) { \
|
||||||
M_MEMORY_FULL((size_t)-1); \
|
M_MEMORY_FULL((size_t)-1); \
|
||||||
|
|||||||
+5
-5
@@ -126,23 +126,23 @@ m_serial_bin_write_integer(m_serial_write_t serial,const long long data, const s
|
|||||||
FILE *f = (FILE *)serial->data[0].p;
|
FILE *f = (FILE *)serial->data[0].p;
|
||||||
switch (size_of_type) {
|
switch (size_of_type) {
|
||||||
case 1:
|
case 1:
|
||||||
i8 = data;
|
i8 = (int8_t) data;
|
||||||
n = fwrite (M_ASSIGN_CAST(const void*, &i8), sizeof i8, 1, f);
|
n = fwrite (M_ASSIGN_CAST(const void*, &i8), sizeof i8, 1, f);
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
i16 = data;
|
i16 = (int16_t) data;
|
||||||
n = fwrite (M_ASSIGN_CAST(const void*, &i16), sizeof i16, 1, f);
|
n = fwrite (M_ASSIGN_CAST(const void*, &i16), sizeof i16, 1, f);
|
||||||
break;
|
break;
|
||||||
case 4:
|
case 4:
|
||||||
i32 = data;
|
i32 = (int32_t) data;
|
||||||
n = fwrite (M_ASSIGN_CAST(const void*, &i32), sizeof i32, 1, f);
|
n = fwrite (M_ASSIGN_CAST(const void*, &i32), sizeof i32, 1, f);
|
||||||
break;
|
break;
|
||||||
case 8:
|
case 8:
|
||||||
i64 = data;
|
i64 = (int64_t) data;
|
||||||
n = fwrite (M_ASSIGN_CAST(const void*, &i64), sizeof i64, 1, f);
|
n = fwrite (M_ASSIGN_CAST(const void*, &i64), sizeof i64, 1, f);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
M_ASSERT_INIT(false, "an integer of suitable size");
|
M_ASSERT_INIT(false, "an integer of suitable size (8/16/32/64)");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return n == 1 ? M_SERIAL_OK_DONE : m_core_serial_fail();
|
return n == 1 ? M_SERIAL_OK_DONE : m_core_serial_fail();
|
||||||
|
|||||||
+1
-1
@@ -118,7 +118,7 @@ stringi_set_size(string_t s, size_t size)
|
|||||||
// Function can be called when contract is not fullfilled
|
// Function can be called when contract is not fullfilled
|
||||||
if (stringi_stack_p(s)) {
|
if (stringi_stack_p(s)) {
|
||||||
assert (size < sizeof (string_heap_t) - 1);
|
assert (size < sizeof (string_heap_t) - 1);
|
||||||
s->u.stack.buffer[sizeof (string_heap_t) - 1] = size;
|
s->u.stack.buffer[sizeof (string_heap_t) - 1] = (char) size;
|
||||||
} else
|
} else
|
||||||
s->u.heap.size = size;
|
s->u.heap.size = size;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user