diff --git a/pcu/pcu_util.h b/pcu/pcu_util.h index 63aa49a30..e61394e51 100644 --- a/pcu/pcu_util.h +++ b/pcu/pcu_util.h @@ -22,24 +22,24 @@ void PCU_Assert_Fail(const char* msg) __attribute__ ((noreturn)); } /* extern "C" */ #endif -#define PCU_ALWAYS_ASSERT(cond) \ - do { \ - if (! (cond)) { \ - char omsg[2048]; \ - sprintf(omsg, "%s failed at %s + %d \n", \ - #cond, __FILE__, __LINE__); \ - PCU_Assert_Fail(omsg); \ - } \ +#define PCU_ALWAYS_ASSERT(cond) \ + do { \ + if (! (cond)) { \ + char omsg[2048]; \ + snprintf(omsg, 2048, "%s failed at %s + %d \n", \ + #cond, __FILE__, __LINE__); \ + PCU_Assert_Fail(omsg); \ + } \ } while (0) -#define PCU_ALWAYS_ASSERT_VERBOSE(cond, msg) \ - do { \ - if (! (cond)) { \ - char omsg[2048]; \ - sprintf(omsg, "%s failed at %s + %d \n %s", \ - #cond, __FILE__, __LINE__, msg); \ - PCU_Assert_Fail(omsg); \ - } \ +#define PCU_ALWAYS_ASSERT_VERBOSE(cond, msg) \ + do { \ + if (! (cond)) { \ + char omsg[2048]; \ + snprintf(omsg, 2048, "%s failed at %s + %d \n %s", \ + #cond, __FILE__, __LINE__, msg); \ + PCU_Assert_Fail(omsg); \ + } \ } while(0) #ifdef NDEBUG diff --git a/phasta/phBubble.cc b/phasta/phBubble.cc index 70e00deba..b155440c4 100644 --- a/phasta/phBubble.cc +++ b/phasta/phBubble.cc @@ -23,7 +23,7 @@ void readBubbles(Bubbles& bubbles, std::string bubbleFileName) FILE *filebubble; Bubble readbubble; - sprintf(bubblefname, "%s", bubbleFileName.c_str()); + snprintf(bubblefname, 1024, "%s", bubbleFileName.c_str()); if (!PCU_Comm_Self()) lion_oprint(1,"reading bubbles info from %s\n",bubblefname); diff --git a/phasta/phiotimer.cc b/phasta/phiotimer.cc index ecc1f7b40..6e1a9502c 100644 --- a/phasta/phiotimer.cc +++ b/phasta/phiotimer.cc @@ -114,7 +114,7 @@ void phastaio_addWriteTime(size_t t) { } void phastaio_setfile(int f) { - char msg[64]; sprintf(msg, "f %d", f); + char msg[64]; snprintf(msg, 64, "f %d", f); PCU_ALWAYS_ASSERT_VERBOSE(f >= 0 && f < NUM_PHASTAIO_MODES, msg); phastaio_global_stats.fileIdx = f; } diff --git a/pumi-meshes b/pumi-meshes index c00ba9c16..61048f847 160000 --- a/pumi-meshes +++ b/pumi-meshes @@ -1 +1 @@ -Subproject commit c00ba9c16cacbb361ee538c03a3ec694ddb989f2 +Subproject commit 61048f84713c15182d6cee972e035552e66564ea diff --git a/test/matchedNodeElmReader.cc b/test/matchedNodeElmReader.cc index 4dfdfabd0..7175b531a 100644 --- a/test/matchedNodeElmReader.cc +++ b/test/matchedNodeElmReader.cc @@ -675,7 +675,7 @@ void readMesh(const char* meshfilename, int self = PCU_Comm_Self(); char filename[1024]; - sprintf(filename, "%s.%d",coordfilename,self); + snprintf(filename, 1024, "%s.%d",coordfilename,self); FILE* fc = fopen(filename , "r"); PCU_ALWAYS_ASSERT(fc); @@ -689,14 +689,14 @@ void readMesh(const char* meshfilename, fclose(fc); if(0==1) { - sprintf(filename, "%s.%d",solutionfilename,self); + snprintf(filename, 1024, "%s.%d",solutionfilename,self); FILE* fs = fopen(filename, "r"); PCU_ALWAYS_ASSERT(fs); readSolution(fs, mesh.localNumVerts, &(mesh.solution)); fclose(fs); } - sprintf(filename, "%s.%d",classfilename,self); + snprintf(filename, 1024, "%s.%d",classfilename,self); FILE* ff = fopen(filename, "r"); PCU_ALWAYS_ASSERT(ff); readClassification(ff, mesh.localNumVerts, &(mesh.classification)); @@ -704,7 +704,7 @@ void readMesh(const char* meshfilename, if( strcmp(fathers2Dfilename, "NULL") ) { //add an argument to readMesh for the fathers2D - sprintf(filename, "%s.%d",fathers2Dfilename,self); + snprintf(filename, 1024, "%s.%d",fathers2Dfilename,self); FILE* fff = fopen(filename, "r"); PCU_ALWAYS_ASSERT(fff); readFathers(fff, mesh.localNumVerts, &(mesh.fathers2D)); @@ -712,7 +712,7 @@ void readMesh(const char* meshfilename, } if( strcmp(matchfilename, "NULL") ) { - sprintf(filename, "%s.%d",matchfilename,self); + snprintf(filename, 1024, "%s.%d",matchfilename,self); FILE* fm = fopen(filename, "r"); PCU_ALWAYS_ASSERT(fm); readMatches(fm, mesh.numVerts, mesh.localNumVerts, &(mesh.matches)); diff --git a/test/measureAnisoStats.cc b/test/measureAnisoStats.cc index 4b67c380f..4bedbe673 100644 --- a/test/measureAnisoStats.cc +++ b/test/measureAnisoStats.cc @@ -158,12 +158,12 @@ void getStats( char message[512]; // first find the sizes field sizes = m->findField(sizeName); - sprintf(message, "Couldn't find a field with name %s in mesh!", sizeName); + snprintf(message, 512, "Couldn't find a field with name %s in mesh!", sizeName); PCU_ALWAYS_ASSERT_VERBOSE(sizes, message); // then find the frames field if they exist frames = m->findField(frameName); - sprintf(message, "Couldn't find a field with name %s in mesh!", frameName); + snprintf(message, 512, "Couldn't find a field with name %s in mesh!", frameName); PCU_ALWAYS_ASSERT_VERBOSE(frames, message); } diff --git a/test/measureIsoStats.cc b/test/measureIsoStats.cc index ac523843a..ed9dd09e7 100644 --- a/test/measureIsoStats.cc +++ b/test/measureIsoStats.cc @@ -154,7 +154,7 @@ void getStats( char message[512]; // first find the sizes field sizes = m->findField(sizeName); - sprintf(message, "Couldn't find a field with name %s in mesh!", sizeName); + snprintf(message, 512, "Couldn't find a field with name %s in mesh!", sizeName); PCU_ALWAYS_ASSERT_VERBOSE(sizes, message); } diff --git a/test/print_pumipic_partition.cc b/test/print_pumipic_partition.cc index 3a6be4bc8..999156d6f 100644 --- a/test/print_pumipic_partition.cc +++ b/test/print_pumipic_partition.cc @@ -58,7 +58,7 @@ int main(int argc, char** argv) //Write the partition out char filename[256]; - sprintf(filename , "%s_%d.ptn", argv[4], num_ranks); + snprintf(filename , 256, "%s_%d.ptn", argv[4], num_ranks); printf("Writing partition to %s\n", filename); std::ofstream out(filename); apf::MeshIterator* mitr = m->begin(m->getDimension()); diff --git a/test/visualizeAnisoSizes.cc b/test/visualizeAnisoSizes.cc index 00a1c2178..3f461860e 100644 --- a/test/visualizeAnisoSizes.cc +++ b/test/visualizeAnisoSizes.cc @@ -163,12 +163,12 @@ void visualizeSizeField( char message[512]; // first find the sizes field sizes = m->findField(sizeName); - sprintf(message, "Couldn't find a field with name %s in mesh!", sizeName); + snprintf(message, 512, "Couldn't find a field with name %s in mesh!", sizeName); PCU_ALWAYS_ASSERT_VERBOSE(sizes, message); // then find the frames field if they exist frames = m->findField(frameName); - sprintf(message, "Couldn't find a field with name %s in mesh!", frameName); + snprintf(message, 512, "Couldn't find a field with name %s in mesh!", frameName); PCU_ALWAYS_ASSERT_VERBOSE(frames, message); }