Commit 7ccc6ee4 authored by miller86's avatar miller86

Fixed a warning from an SNPRINTF statement in avtGenericDatabase regarding %d and vtkIdtype

Added C_strndup utility function mimicing CXX variants but using malloc
Used C_strndup in Exodus plugin and in Namescheme.C


git-svn-id: http://visit.ilight.com/svn/visit/trunk/src@21670 18c085ea-50e0-402c-830e-de6fd14e8384
parent 1becf53c
...@@ -3684,7 +3684,7 @@ avtGenericDatabase::MaterialSelect(vtkDataSet *ds, avtMaterial *mat, ...@@ -3684,7 +3684,7 @@ avtGenericDatabase::MaterialSelect(vtkDataSet *ds, avtMaterial *mat,
char msg[128]; char msg[128];
SNPRINTF(msg,sizeof(msg),"In domain number %d, the material object " SNPRINTF(msg,sizeof(msg),"In domain number %d, the material object "
"with nzones=%d and dataset object with ncells=%d do not agree.", "with nzones=%d and dataset object with ncells=%d do not agree.",
dom, mat->GetNZones(), ds->GetNumberOfCells()); dom, mat->GetNZones(), (int) ds->GetNumberOfCells());
EXCEPTION1(InvalidDBTypeException, msg); EXCEPTION1(InvalidDBTypeException, msg);
} }
......
...@@ -43,6 +43,7 @@ ...@@ -43,6 +43,7 @@
#include <limits.h> #include <limits.h>
#include <string.h> #include <string.h>
#include <Namescheme.h> #include <Namescheme.h>
#include <Utility.h>
#define FREE(M) if(M)free(M); #define FREE(M) if(M)free(M);
...@@ -365,9 +366,7 @@ Namescheme::Namescheme(const char *fmt, ...) ...@@ -365,9 +366,7 @@ Namescheme::Namescheme(const char *fmt, ...)
return; return;
// grab just the part of fmt that is the printf-style format string // grab just the part of fmt that is the printf-style format string
this->fmt = (char *)calloc(n, sizeof(char)); this->fmt = C_strndup(&fmt[1],n-1);
strncpy(this->fmt, &fmt[1], n-1);
this->fmtlen = n-1; this->fmtlen = n-1;
// In 2 passes, count conversion specs. and then setup pointers to each // In 2 passes, count conversion specs. and then setup pointers to each
......
...@@ -88,6 +88,7 @@ bool UTILITY_API ConvertArgsToTunneledValues(const std::map<int,int>&, ...@@ -88,6 +88,7 @@ bool UTILITY_API ConvertArgsToTunneledValues(const std::map<int,int>&,
bool UTILITY_API GetSSHClient(std::string &sshClient); bool UTILITY_API GetSSHClient(std::string &sshClient);
inline char *C_strdup(char const * const); inline char *C_strdup(char const * const);
inline char *C_strndup(char const * const, size_t);
inline char *CXX_strdup(char const * const); inline char *CXX_strdup(char const * const);
inline char *CXX_strndup(char const * const, size_t); inline char *CXX_strndup(char const * const, size_t);
inline void InlineCopy(char *&, const char * const &, const int &); inline void InlineCopy(char *&, const char * const &, const int &);
...@@ -125,6 +126,15 @@ C_strdup(char const * const c) ...@@ -125,6 +126,15 @@ C_strdup(char const * const c)
return p; return p;
} }
inline char *
C_strndup(char const * const c, size_t n)
{
size_t len = (strlen(c) < n) ? strlen(c) : n;
char *p = (char *) malloc(len+1);
memcpy(p, c, len);
p[len] = '\0';
return p;
}
// **************************************************************************** // ****************************************************************************
// Method: CXX_strdup // Method: CXX_strdup
......
...@@ -84,6 +84,7 @@ ...@@ -84,6 +84,7 @@
#include <InvalidVariableException.h> #include <InvalidVariableException.h>
#include <InvalidFilesException.h> #include <InvalidFilesException.h>
#include <UnexpectedValueException.h> #include <UnexpectedValueException.h>
#include <Utility.h>
#include <string.h> #include <string.h>
#include <boost/cstdint.hpp> #include <boost/cstdint.hpp>
...@@ -202,11 +203,7 @@ static char **GetStringListFromExodusIINCvar(int exfid, char const *var_name) ...@@ -202,11 +203,7 @@ static char **GetStringListFromExodusIINCvar(int exfid, char const *var_name)
char *p; char *p;
retval = (char**) malloc((nstrings + 1) * sizeof(char*)); retval = (char**) malloc((nstrings + 1) * sizeof(char*));
for (i = 0, p = buf; i < nstrings; i++, p += len_string) for (i = 0, p = buf; i < nstrings; i++, p += len_string)
{ retval[i] = C_strndup(p,len_string);
// retval[i] = strndup(p,len_string);
retval[i] = (char*) malloc((len_string + 1) * sizeof(char));
strncpy( retval[i], p, len_string );
}
retval[i] = 0; retval[i] = 0;
free(buf); free(buf);
...@@ -250,9 +247,11 @@ static int SizeOfNCType(int type) ...@@ -250,9 +247,11 @@ static int SizeOfNCType(int type)
case NC_INT: case NC_INT:
case NC_UINT: case NC_UINT:
return sizeof(int); return sizeof(int);
#ifdef HAVE_VTK_SIZEOF___INT64
case NC_INT64: case NC_INT64:
case NC_UINT64: case NC_UINT64:
return sizeof(int64_t); return sizeof(int64_t);
#endif
case NC_FLOAT: case NC_FLOAT:
return sizeof(float); return sizeof(float);
case NC_DOUBLE: case NC_DOUBLE:
...@@ -851,7 +850,9 @@ GetElementBlockNamesAndIds(int ncExIIId, int numBlocks, ...@@ -851,7 +850,9 @@ GetElementBlockNamesAndIds(int ncExIIId, int numBlocks,
switch (vtype) switch (vtype)
{ {
case NC_INT: READ_BLOCK_IDS(ncExIIId, eb_blockid_varid, numBlocks, blockId, int); break; case NC_INT: READ_BLOCK_IDS(ncExIIId, eb_blockid_varid, numBlocks, blockId, int); break;
// case NC_INT64: READ_BLOCK_IDS(ncExIIId, eb_blockid_varid, numBlocks, blockId, int64_t); break; #ifdef HAVE_VTK_SIZEOF___INT64
case NC_INT64: READ_BLOCK_IDS(ncExIIId, eb_blockid_varid, numBlocks, blockId, int64_t); break;
#endif
} }
} }
......
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