Commit f577114f authored by Kenneth Moreland's avatar Kenneth Moreland

Fix warnings on MSVC

Most of the warnings are about using "unsafe" functions. In addition to
replacing string functions like strcpy with counting strncpy versions,
which makes sense, older MSVC versions for some reason don't support
POSIX versions of these functions. Instead, they have their weird
offshoots, which is a pain.
parent fb903415
File mode changed from 100755 to 100644
......@@ -13,6 +13,7 @@
#include <IceTDevCommunication.h>
#include <IceTDevContext.h>
#include <IceTDevPorting.h>
#include <stdlib.h>
#include <stdio.h>
......@@ -25,6 +26,8 @@
#include <unistd.h>
#endif
#define MAX_MESSAGE_LEN 1024
static IceTEnum currentError = ICET_NO_ERROR;
static IceTEnum currentLevel;
......@@ -66,7 +69,9 @@ void icetRaiseDiagnostic(IceTEnum type,
full_message[0] = '\0';
offset = 0;
#define ADD_TO_MESSAGE(...) \
offset += sprintf(full_message + offset, __VA_ARGS__); \
offset += snprintf(full_message + offset, \
ICET_MESSAGE_SIZE - offset, \
__VA_ARGS__); \
if (offset > ICET_MESSAGE_SIZE) { \
printf("PANIC:%s:%d: Diagnostic message too large!\n", file, line); \
icetStateDump(); \
......
......@@ -81,3 +81,47 @@ IceTInt icetTypeWidth(IceTEnum type)
return 0;
}
#ifndef WIN32
IceTBoolean icetGetEnv(const char *variable_name,
char *buffer,
IceTSizeType buffer_size)
{
const char *value = getenv(variable_name);
if (value != NULL)
{
strncpy(buffer, value, buffer_size);
return ICET_TRUE;
} else {
buffer[0] = '\0';
return ICET_FALSE;
}
}
void icetPutEnv(const char *name, const char *value)
{
setenv(name, value, ICET_TRUE);
}
#else /*WIN32*/
IceTBoolean icetGetEnv(const char *variable_name,
char *buffer,
IceTSizeType buffer_size)
{
size_t required_size; /* Not really used. */
errno_t error;
error = getenv_s(&required_size, buffer, buffer_size, variable_name);
if ((error == 0) && (required_size > 0))
{
return ICET_TRUE;
} else {
buffer[0] = '\0';
return ICET_FALSE;
}
}
void icetPutEnv(const char *name, const char *value)
{
_putenv_s(name, value);
}
#endif /*WIN32*/
......@@ -122,6 +122,8 @@ void icetStateSetDefaults(void)
IceTInt *int_array;
int i;
int comm_size, comm_rank;
#define ENV_BUFFER_LEN 128
char env_buffer[128];
icetDiagnostics(ICET_DIAG_ALL_NODES | ICET_DIAG_WARNINGS);
......@@ -157,8 +159,8 @@ void icetStateSetDefaults(void)
icetStateSetInteger(ICET_DATA_REPLICATION_GROUP_SIZE, 1);
icetStateSetInteger(ICET_FRAME_COUNT, 0);
if (getenv("ICET_MAGIC_K") != NULL) {
IceTInt magic_k = atoi(getenv("ICET_MAGIC_K"));
if (icetGetEnv("ICET_MAGIC_K", env_buffer, ENV_BUFFER_LEN)) {
IceTInt magic_k = atoi(env_buffer);
if (magic_k > 1) {
icetStateSetInteger(ICET_MAGIC_K, magic_k);
} else {
......@@ -171,8 +173,8 @@ void icetStateSetDefaults(void)
icetStateSetInteger(ICET_MAGIC_K, ICET_MAGIC_K_DEFAULT);
}
if (getenv("ICET_MAX_IMAGE_SPLIT") != NULL) {
IceTInt max_image_split = atoi(getenv("ICET_MAX_IMAGE_SPLIT"));
if (icetGetEnv("ICET_MAX_IMAGE_SPLIT", env_buffer, ENV_BUFFER_LEN)) {
IceTInt max_image_split = atoi(env_buffer);
if (max_image_split > 0) {
icetStateSetInteger(ICET_MAX_IMAGE_SPLIT, max_image_split);
} else {
......
......@@ -131,6 +131,7 @@ int icetAddTile(IceTInt x, IceTInt y, IceTSizeType width, IceTSizeType height,
/* Return index to tile. */
return num_tiles;
#undef MSG_LEN
}
void icetPhysicalRenderSize(IceTInt width, IceTInt height)
......
......@@ -11,7 +11,6 @@
#define __IceTDevDiagnostics_h
#include <IceT.h>
#include <stdio.h>
#ifdef __cplusplus
extern "C" {
......
......@@ -12,6 +12,9 @@
#include <IceT.h>
#include <stdio.h>
#include <string.h>
#ifdef __cplusplus
extern "C" {
#endif
......@@ -23,6 +26,24 @@ extern "C" {
etc.) in bytes. */
ICET_EXPORT IceTInt icetTypeWidth(IceTEnum type);
#ifdef WIN32
#define snprintf(buffer, size, ...) \
_snprintf_s(buffer, size, _TRUNCATE, __VA_ARGS__)
#define strncpy(dest, src, size) strncpy_s(dest, size, src, _TRUNCATE)
#define fdopen _fdopen
#endif
/* A portable version of getenv. This version requires you to give a buffer
to result the result into. Returns ICET_TRUE if the environment variable
was found.*/
ICET_EXPORT IceTBoolean icetGetEnv(const char *variable_name,
char *buffer,
IceTSizeType buffer_size);
/* A portable version of putenv. This version takes the variable name and
value as separate arguments. */
ICET_EXPORT void icetPutEnv(const char *name, const char *value);
#ifdef __cplusplus
}
#endif
......
......@@ -15,6 +15,9 @@
*****************************************************************************/
#include <IceTGL.h>
#include <IceTDevPorting.h>
#include "test_codes.h"
#include "test_util.h"
......@@ -107,9 +110,10 @@ static void DisplayNoDrawDoTest(void)
if (bad_count >= 10) {
char filename[256];
global_result = TEST_FAILED;
sprintf(filename, "DisplayNoDraw_%s_%s_%d.ppm",
icetGetStrategyName(), icetGetSingleImageStrategyName(),
global_iteration);
snprintf(filename, 256, "DisplayNoDraw_%s_%s_%d.ppm",
icetGetStrategyName(),
icetGetSingleImageStrategyName(),
global_iteration);
write_ppm(filename, color_buffer,
(int)SCREEN_WIDTH, (int)SCREEN_HEIGHT);
}
......
......@@ -16,6 +16,7 @@
#include <IceTDevCommunication.h>
#include <IceTDevMatrix.h>
#include <IceTDevPorting.h>
#include <stdlib.h>
#include <stdio.h>
......@@ -60,7 +61,7 @@ static IceTBoolean CheckPixel(const IceTImage image,
buffer = malloc(4*icetImageGetWidth(image)*icetImageGetHeight(image));
icetImageCopyColorub(image, buffer, ICET_IMAGE_COLOR_RGBA_UBYTE);
icetGetIntegerv(ICET_RANK, &rank);
sprintf(filename, "FloatingViewport_%d.ppm", rank);
snprintf(filename, 255, "FloatingViewport_%d.ppm", rank);
write_ppm(filename,
buffer,
icetImageGetWidth(image),
......
......@@ -24,7 +24,7 @@
/* Just something to set in the depth. */
#define ACTIVE_DEPTH(x, y) \
(((x)+(y)+1.0)/10000.0)
(((x)+(y)+1.0f)/10000.0f)
/* Fills the given image to have data in the lower triangle like this:
*
......
......@@ -16,6 +16,7 @@
#include <IceTDevContext.h>
#include <IceTDevMatrix.h>
#include <IceTDevPorting.h>
#include <stdlib.h>
#include <stdio.h>
......@@ -252,13 +253,8 @@ static int MaxImageSplitTryMax()
printstat("Trying max image split of %d\n", max_image_split);
#ifdef _WIN32
sprintf(image_split_string, "ICET_MAX_IMAGE_SPLIT=%d", max_image_split);
putenv(image_split_string);
#else
sprintf(image_split_string, "%d", max_image_split);
setenv("ICET_MAX_IMAGE_SPLIT", image_split_string, ICET_TRUE);
#endif
snprintf(image_split_string, 64, "%d", max_image_split);
icetPutEnv("ICET_MAX_IMAGE_SPLIT", image_split_string);
/* This is a bit hackish. The max image split value is set when the
IceT context is initialized. Thus, for the environment to take
......
......@@ -11,8 +11,9 @@
#include <IceTGL.h>
#include <IceTDevCommunication.h>
#include <IceTDevState.h>
#include <IceTDevImage.h>
#include <IceTDevPorting.h>
#include <IceTDevState.h>
#include "test_codes.h"
#include "test_util.h"
......@@ -119,9 +120,9 @@ static int compare_color_buffers(IceTSizeType local_width,
/* Too many errors. Call it bad. */
printrank("Too many bad pixels!!!!!!\n");
/* Write current images. */
sprintf(filename, "ref%03d.ppm", rank);
snprintf(filename, FILENAME_MAX, "ref%03d.ppm", rank);
write_ppm(filename, refcbuf, (int)SCREEN_WIDTH, (int)SCREEN_HEIGHT);
sprintf(filename, "bad%03d.ppm", rank);
snprintf(filename, FILENAME_MAX, "bad%03d.ppm", rank);
write_ppm(filename, cb, (int)local_width, (int)local_height);
/* Write difference image. */
for (y = 0; y < local_height; y++) {
......@@ -145,7 +146,7 @@ static int compare_color_buffers(IceTSizeType local_width,
}
}
}
sprintf(filename, "diff%03d.ppm", rank);
snprintf(filename, FILENAME_MAX, "diff%03d.ppm", rank);
write_ppm(filename, cb, (int)local_width, (int)local_height);
return 0;
}
......@@ -236,7 +237,7 @@ static int compare_depth_buffers(IceTSizeType local_width,
encoded[3] = 255;
}
}
sprintf(filename, "depth_error%03d.ppm", rank);
snprintf(filename, FILENAME_MAX, "depth_error%03d.ppm", rank);
write_ppm(filename, (IceTUByte *)errbuf,
(int)local_width, (int)local_height);
......
......@@ -44,8 +44,10 @@ static void GetSphereArrays(GLfloat **vertex_array_p, GLfloat **normal_array_p)
// Fill out tables.
for (theta_index = 0; theta_index <= SPHERE_RESOLUTION; theta_index++)
{
cos_table[theta_index]=cosf((2*M_PI/SPHERE_RESOLUTION)*theta_index);
sin_table[theta_index]=sinf((2*M_PI/SPHERE_RESOLUTION)*theta_index);
cos_table[theta_index] =
(GLfloat)cos((2*M_PI/SPHERE_RESOLUTION)*theta_index);
sin_table[theta_index] =
(GLfloat)sin((2*M_PI/SPHERE_RESOLUTION)*theta_index);
}
// Compute the vertices and normals.
......
......@@ -13,6 +13,7 @@
#include <IceTDevContext.h>
#include <IceTDevImage.h>
#include <IceTDevMatrix.h>
#include <IceTDevPorting.h>
#include "test_util.h"
#include "test_codes.h"
......@@ -419,7 +420,7 @@ static void draw(const IceTDouble *projection_matrix,
* IceT will not recognize as background. */
background_depth = 0.999f;
background_alpha
= (background_color[3] == 0) ? 0.001 : background_color[3];
= (background_color[3] == 0) ? 0.001f : background_color[3];
/* Clear out the the images to background so that pixels outside of
* the contained viewport have valid values. */
......@@ -1112,14 +1113,14 @@ static int SimpleTimingDoRender()
IceTInt magic_k;
icetGetIntegerv(ICET_MAGIC_K, &magic_k);
sprintf(name_buffer, "radix-k %d", (int)magic_k);
snprintf(name_buffer, 256, "radix-k %d", (int)magic_k);
si_strategy_name = name_buffer;
} else if (g_single_image_strategy == ICET_SINGLE_IMAGE_STRATEGY_RADIXKR) {
static char name_buffer[256];
IceTInt magic_k;
icetGetIntegerv(ICET_MAGIC_K, &magic_k);
sprintf(name_buffer, "radix-kr %d", (int)magic_k);
snprintf(name_buffer, 256, "radix-kr %d", (int)magic_k);
si_strategy_name = name_buffer;
} else {
si_strategy_name = icetGetSingleImageStrategyName();
......@@ -1270,7 +1271,7 @@ static int SimpleTimingDoRender()
IceTUByte *buffer = malloc(SCREEN_WIDTH*SCREEN_HEIGHT*4);
char filename[256];
icetImageCopyColorub(image, buffer, ICET_IMAGE_COLOR_RGBA_UBYTE);
sprintf(filename, "SimpleTiming%02d.ppm", rank);
snprintf(filename, 256, "SimpleTiming%02d.ppm", rank);
write_ppm(filename, buffer, (int)SCREEN_WIDTH, (int)SCREEN_HEIGHT);
free(buffer);
}
......@@ -1347,13 +1348,8 @@ static int SimpleTimingDoParameterStudies()
char k_string[64];
int retval;
#ifdef _WIN32
sprintf(k_string, "ICET_MAGIC_K=%d", magic_k);
putenv(k_string);
#else
sprintf(k_string, "%d", magic_k);
setenv("ICET_MAGIC_K", k_string, ICET_TRUE);
#endif
snprintf(k_string, 64, "%d", magic_k);
icetPutEnv("ICET_MAGIC_K", k_string);
/* This is a bit hackish. The magic k value is set when the IceT
context is initialized. Thus, for the environment to take
......@@ -1389,13 +1385,8 @@ static int SimpleTimingDoParameterStudies()
char image_split_string[64];
int retval;
#ifdef _WIN32
sprintf(image_split_string, "ICET_MAX_IMAGE_SPLIT=%d", image_split);
putenv(image_split_string);
#else
sprintf(image_split_string, "%d", image_split);
setenv("ICET_MAX_IMAGE_SPLIT", image_split_string, ICET_TRUE);
#endif
snprintf(image_split_string, 64, "%d", image_split);
icetPutEnv("ICET_MAX_IMAGE_SPLIT", image_split_string);
/* This is a bit hackish. The max image split value is set when the
IceT context is initialized. Thus, for the environment to take
......
......@@ -22,7 +22,11 @@ void write_ppm(const char *filename,
int x, y;
const unsigned char *color;
#ifndef WIN32
fd = fopen(filename, "wb");
#else /*WIN32*/
fopen_s(&fd, filename, "wb");
#endif /*WIN32*/
fprintf(fd, "P6\n");
fprintf(fd, "# %s generated by IceT test suite.\n", filename);
......
......@@ -11,6 +11,7 @@
#include "test_codes.h"
#include <IceTDevCommunication.h>
#include <IceTDevPorting.h>
#ifndef __USE_POSIX
#define __USE_POSIX
......@@ -29,6 +30,7 @@
#include <unistd.h>
#else
#include <io.h>
#include <share.h>
#define dup(fildes) _dup(fildes)
#define dup2(fildes, fildes2) _dup2(fildes, fildes2)
#endif
......@@ -218,12 +220,23 @@ void initialize_test(int *argcp, char ***argvp, IceTCommunicator comm)
} else {
realstdout = NULL;
}
sprintf(filename, "log.%04d", rank);
snprintf(filename, 64, "log.%04d", rank);
#ifndef WIN32
outfd = open(filename, O_WRONLY | O_CREAT | O_APPEND, 0644);
if (outfd < 0) {
printf("Could not open %s for writing.\n", filename);
exit(1);
}
#else /*WIN32*/
if (_sopen_s(&outfd,
filename,
O_WRONLY | O_CREAT | O_APPEND,
_SH_DENYNO,
0644) != 0) {
printf("Could not open %s for writing.\n", filename);
exit(1);
}
#endif /*WIN32*/
dup2(outfd, 1);
} else {
realstdout = stdout;
......@@ -257,7 +270,7 @@ IceTBoolean strategy_uses_single_image_strategy(IceTEnum strategy)
}
}
int run_test_base(int (*test_function)(void))
int run_test_base(int (*test_function)())
{
int result;
......
......@@ -13,7 +13,7 @@
#include "test_util.h"
#include <IceTMPI.h>
extern int run_test_base(int (*test_function)(void));
extern int run_test_base(int (*test_function)());
void init_mpi(int *argcp, char ***argvp)
{
......
......@@ -80,7 +80,7 @@ void init_mpi_opengl(int *argcp, char ***argvp)
}
#if defined(ICET_TESTS_USE_GLUT)
static int (*g_test_function)(void);
static int (*g_test_function)();
static void no_op()
{
......@@ -102,13 +102,13 @@ static void glut_draw()
exit(result);
}
int run_test(int (*test_function)(void))
int run_test(int (*test_function)())
{
/* Record the test function so we can run it in the Glut draw callback. */
g_test_function = test_function;
glutDisplayFunc(no_op);
glutIdleFunc(glut_draw);
glutDisplayFunc((void (*)(void))no_op);
glutIdleFunc((void (*)(void))glut_draw);
/* Glut will reliably create the OpenGL context only after the main loop is
* started. This will create the window and then call our glut_draw function
......
......@@ -32,7 +32,7 @@ extern IceTSizeType SCREEN_HEIGHT;
void initialize_test(int *argcp, char ***argvp, IceTCommunicator comm);
int run_test(int (*test_function)(void));
int run_test(int (*test_function)());
/* Used like printf but prints status only on process 0 or to independent
logs. */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment