Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix arguments inconsistent with their format strings #143

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/libqhull/global.c
Original file line number Diff line number Diff line change
Expand Up @@ -2248,7 +2248,7 @@ void qh_lib_check(int qhullLibraryType, int qhTsize, int vertexTsize, int ridgeT
last_errcode= 6253;
}
if (qhmemTsize && qhmemTsize != sizeof(qhmemT)) {
qh_fprintf_stderr(6254, "qh_lib_check: Incorrect qhull library called. Size of qhmemT for caller is %d, but for qhull library is %d.\n", qhmemTsize, sizeof(qhmemT));
qh_fprintf_stderr(6254, "qh_lib_check: Incorrect qhull library called. Size of qhmemT for caller is %d, but for qhull library is %d.\n", qhmemTsize, (int)sizeof(qhmemT));
last_errcode= 6254;
}
if (last_errcode) {
Expand Down
2 changes: 1 addition & 1 deletion src/libqhull/io.c
Original file line number Diff line number Diff line change
Expand Up @@ -1618,7 +1618,7 @@ void qh_printcenter(FILE *fp, qh_PRINT format, const char *string, facetT *facet
if (qh CENTERtype != qh_ASvoronoi && qh CENTERtype != qh_AScentrum)
return;
if (string)
qh_fprintf(fp, 9066, string);
qh_fprintf(fp, 9066, "%s", string);
if (qh CENTERtype == qh_ASvoronoi) {
num= qh hull_dim-1;
if (!facet->normal || !facet->upperdelaunay || !qh ATinfinity) {
Expand Down
13 changes: 10 additions & 3 deletions src/libqhull/libqhull.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,13 @@
#endif
#endif

#if defined(__GNUC__)
/* See https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-format-function-attribute */
#define QH_PRINTF_LIKE(string_index, first_to_check) __attribute__((format(printf, string_index, first_to_check)))
#else
#define QH_PRINTF_LIKE(string_index, first_to_check)
#endif

/*============ constants and basic types ====================*/

extern const char qh_version[]; /* defined in global.c */
Expand Down Expand Up @@ -1136,13 +1143,13 @@ void qh_user_memsizes(void);

/********* -usermem.c prototypes (alphabetical) **********************/
void qh_exit(int exitcode);
void qh_fprintf_stderr(int msgcode, const char *fmt, ... );
void qh_fprintf_stderr(int msgcode, const char *fmt, ... ) QH_PRINTF_LIKE(2, 3);
void qh_free(void *mem);
void *qh_malloc(size_t size);

/********* -userprintf.c and userprintf_rbox.c prototypes **********************/
void qh_fprintf(FILE *fp, int msgcode, const char *fmt, ... );
void qh_fprintf_rbox(FILE *fp, int msgcode, const char *fmt, ... );
void qh_fprintf(FILE *fp, int msgcode, const char *fmt, ... ) QH_PRINTF_LIKE(3, 4);
void qh_fprintf_rbox(FILE *fp, int msgcode, const char *fmt, ... ) QH_PRINTF_LIKE(3, 4);

/***** -geom.c/geom2.c/random.c prototypes (duplicated from geom.h, random.h) ****************/

Expand Down
11 changes: 5 additions & 6 deletions src/libqhull/merge.c
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ void qh_appendmergeset(facetT *facet, facetT *neighbor, mergeType mergetype, coo
return;
}
if (!qh facet_mergeset || !qh degen_mergeset) {
qh_fprintf(qh ferr, 6403, "qhull internal error (qh_appendmergeset): expecting temp set defined for qh.facet_mergeset (0x%x) and qh.degen_mergeset (0x%x). Got NULL\n",
qh_fprintf(qh ferr, 6403, "qhull internal error (qh_appendmergeset): expecting temp set defined for qh.facet_mergeset (%p) and qh.degen_mergeset (%p). Got NULL\n",
qh facet_mergeset, qh degen_mergeset);
/* otherwise qh_setappend creates a new set that is not freed by qh_freebuild() */
qh_errexit(qh_ERRqhull, NULL, NULL);
Expand Down Expand Up @@ -513,8 +513,7 @@ void qh_appendvertexmerge(vertexT *vertex, vertexT *destination, mergeType merge
const char *mergename;

if (!qh vertex_mergeset) {
qh_fprintf(qh ferr, 6387, "qhull internal error (qh_appendvertexmerge): expecting temp set defined for qh.vertex_mergeset (0x%x). Got NULL\n",
qh vertex_mergeset);
qh_fprintf(qh ferr, 6387, "qhull internal error (qh_appendvertexmerge): expecting temp set defined for qh.vertex_mergeset. Got NULL\n");
/* otherwise qh_setappend creates a new set that is not freed by qh_freebuild() */
qh_errexit(qh_ERRqhull, NULL, NULL);
}
Expand Down Expand Up @@ -1654,7 +1653,7 @@ void qh_forcedmerges(boolT *wasmerge) {
void qh_freemergesets(void) {

if (!qh facet_mergeset || !qh degen_mergeset || !qh vertex_mergeset) {
qh_fprintf(qh ferr, 6388, "qhull internal error (qh_freemergesets): expecting mergesets. Got a NULL mergeset, qh.facet_mergeset (0x%x), qh.degen_mergeset (0x%x), qh.vertex_mergeset (0x%x)\n",
qh_fprintf(qh ferr, 6388, "qhull internal error (qh_freemergesets): expecting mergesets. Got a NULL mergeset, qh.facet_mergeset (%p), qh.degen_mergeset (%p), qh.vertex_mergeset (%p)\n",
qh facet_mergeset, qh degen_mergeset, qh vertex_mergeset);
qh_errexit(qh_ERRqhull, NULL, NULL);
}
Expand Down Expand Up @@ -2034,7 +2033,7 @@ ridgeT *qh_hashridge_find(setT *hashtable, int hashsize, ridgeT *ridge,
void qh_initmergesets(void /* qh.facet_mergeset,degen_mergeset,vertex_mergeset */) {

if (qh facet_mergeset || qh degen_mergeset || qh vertex_mergeset) {
qh_fprintf(qh ferr, 6386, "qhull internal error (qh_initmergesets): expecting NULL mergesets. Got qh.facet_mergeset (0x%x), qh.degen_mergeset (0x%x), qh.vertex_mergeset (0x%x)\n",
qh_fprintf(qh ferr, 6386, "qhull internal error (qh_initmergesets): expecting NULL mergesets. Got qh.facet_mergeset (%p), qh.degen_mergeset (%p), qh.vertex_mergeset (%p)\n",
qh facet_mergeset, qh degen_mergeset, qh vertex_mergeset);
qh_errexit(qh_ERRqhull, NULL, NULL);
}
Expand Down Expand Up @@ -2304,7 +2303,7 @@ void qh_maybe_duplicateridge(ridgeT *ridgeA) {
if (k == last) {
vertex= qh_findbest_ridgevertex(ridge, &pinched, &dist);
trace2((qh ferr, 2069, "qh_maybe_duplicateridge: will merge v%d into v%d (dist %2.2g) due to duplicate ridges r%d/r%d with the same vertices. mergevertex set\n",
pinched->id, vertex->id, dist, ridgeA->id, ridge->id, ridgeA->top->id, ridgeA->bottom->id, ridge->top->id, ridge->bottom->id));
pinched->id, vertex->id, dist, ridgeA->id, ridge->id));
qh_appendvertexmerge(pinched, vertex, MRGvertices, dist, ridgeA, ridge);
ridge->mergevertex= True; /* disables check for duplicate vertices in qh_checkfacet */
ridgeA->mergevertex= True;
Expand Down
5 changes: 3 additions & 2 deletions src/libqhull/poly2.c
Original file line number Diff line number Diff line change
Expand Up @@ -1144,7 +1144,7 @@ boolT qh_checklists(facetT *facetlist) {
vertex->visitid= qh vertex_visit;
if (vertex->previous != previousvertex) {
qh_fprintf(qh ferr, 6427, "qhull internal error (qh_checklists): expecting v%d.previous == v%d. Got v%d\n",
vertex->id, previousvertex, getid_(vertex->previous));
vertex->id, previousvertex->id, getid_(vertex->previous));
waserror= True;
errorvertex= vertex;
}
Expand Down Expand Up @@ -2279,7 +2279,8 @@ void qh_initialhull(setT *vertices) {
zzinc_(Zdistcheck);
qh_distplane(qh interior_point, facet, &dist); /* duplicates qh_setfacetplane */
if (dist > qh DISTround) { /* clearly flipped, due to axis-parallel facet or coplanar firstfacet */
trace1((qh ferr, 1031, "qh_initialhull: initial orientation incorrect, qh.interior_point is %2.2g from f%d. Either axis-parallel facet or coplanar firstfacet f%d. Force outside orientation of all facets\n"));
trace1((qh ferr, 1031, "qh_initialhull: initial orientation incorrect, qh.interior_point is %2.2g from f%d. Either axis-parallel facet or coplanar firstfacet f%d. Force outside orientation of all facets\n",
dist, facet->id, firstfacet->id));
FORALLfacets { /* reuse facet, then 'break' */
facet->flipped= False;
facet->toporient ^= (unsigned char)True;
Expand Down
2 changes: 1 addition & 1 deletion src/libqhull_r/global_r.c
Original file line number Diff line number Diff line change
Expand Up @@ -2201,7 +2201,7 @@ void qh_lib_check(int qhullLibraryType, int qhTsize, int vertexTsize, int ridgeT
last_errcode= 6253;
}
if (qhmemTsize && qhmemTsize != sizeof(qhmemT)) {
qh_fprintf_stderr(6254, "qh_lib_check: Incorrect qhull library called. Size of qhmemT for caller is %d, but for qhull library is %d.\n", qhmemTsize, sizeof(qhmemT));
qh_fprintf_stderr(6254, "qh_lib_check: Incorrect qhull library called. Size of qhmemT for caller is %d, but for qhull library is %d.\n", qhmemTsize, (int)sizeof(qhmemT));
last_errcode= 6254;
}
if (last_errcode) {
Expand Down
2 changes: 1 addition & 1 deletion src/libqhull_r/io_r.c
Original file line number Diff line number Diff line change
Expand Up @@ -1618,7 +1618,7 @@ void qh_printcenter(qhT *qh, FILE *fp, qh_PRINT format, const char *string, face
if (qh->CENTERtype != qh_ASvoronoi && qh->CENTERtype != qh_AScentrum)
return;
if (string)
qh_fprintf(qh, fp, 9066, string);
qh_fprintf(qh, fp, 9066, "%s", string);
if (qh->CENTERtype == qh_ASvoronoi) {
num= qh->hull_dim-1;
if (!facet->normal || !facet->upperdelaunay || !qh->ATinfinity) {
Expand Down
13 changes: 10 additions & 3 deletions src/libqhull_r/libqhull_r.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,13 @@
#endif
#endif

#if defined(__GNUC__)
/* See https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-format-function-attribute */
#define QH_PRINTF_LIKE(string_index, first_to_check) __attribute__((format(printf, string_index, first_to_check)))
#else
#define QH_PRINTF_LIKE(string_index, first_to_check)
#endif

/*============ constants and basic types ====================*/

extern const char qh_version[]; /* defined in global_r.c */
Expand Down Expand Up @@ -1132,13 +1139,13 @@ void qh_user_memsizes(qhT *qh);

/********* -usermem_r.c prototypes (alphabetical) **********************/
void qh_exit(int exitcode);
void qh_fprintf_stderr(int msgcode, const char *fmt, ... );
void qh_fprintf_stderr(int msgcode, const char *fmt, ... ) QH_PRINTF_LIKE(2, 3);
void qh_free(void *mem);
void *qh_malloc(size_t size);

/********* -userprintf_r.c and userprintf_rbox_r.c prototypes **********************/
void qh_fprintf(qhT *qh, FILE *fp, int msgcode, const char *fmt, ... );
void qh_fprintf_rbox(qhT *qh, FILE *fp, int msgcode, const char *fmt, ... );
void qh_fprintf(qhT *qh, FILE *fp, int msgcode, const char *fmt, ... ) QH_PRINTF_LIKE(4, 5);
void qh_fprintf_rbox(qhT *qh, FILE *fp, int msgcode, const char *fmt, ... ) QH_PRINTF_LIKE(4, 5);

/***** -geom_r.c/geom2_r.c/random_r.c prototypes (duplicated from geom_r.h, random_r.h) ****************/

Expand Down
4 changes: 2 additions & 2 deletions src/libqhull_r/mem_r.c
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ void qh_memcheck(qhT *qh) {
qh_exit(qhmem_ERRqhull); /* can not use qh_errexit() */
}
if (qh->qhmem.ferr == 0 || qh->qhmem.IStracing < 0 || qh->qhmem.IStracing > 10 || (((qh->qhmem.ALIGNmask+1) & qh->qhmem.ALIGNmask) != 0)) {
qh_fprintf_stderr(6244, "qhull internal error (qh_memcheck): either qh->qhmem is overwritten or qh->qhmem is not initialized. Call qh_meminit or qh_new_qhull before calling qh_mem routines. ferr 0x%x, IsTracing %d, ALIGNmask 0x%x\n",
qh_fprintf_stderr(6244, "qhull internal error (qh_memcheck): either qh->qhmem is overwritten or qh->qhmem is not initialized. Call qh_meminit or qh_new_qhull before calling qh_mem routines. ferr %p, IsTracing %d, ALIGNmask 0x%x\n",
qh->qhmem.ferr, qh->qhmem.IStracing, qh->qhmem.ALIGNmask);
qh_exit(qhmem_ERRqhull); /* can not use qh_errexit() */
}
Expand All @@ -203,7 +203,7 @@ void qh_memcheck(qhT *qh) {
qh_errexit(qh, qhmem_ERRqhull, NULL, NULL);
}
if (qh->qhmem.IStracing != 0)
qh_fprintf(qh, qh->qhmem.ferr, 8144, "qh_memcheck: total size of freelists totfree is the same as qh->qhmem.totfree\n", totfree);
qh_fprintf(qh, qh->qhmem.ferr, 8144, "qh_memcheck: total size of freelists totfree (%d) is the same as qh->qhmem.totfree\n", totfree);
} /* memcheck */

/*-<a href="qh-mem_r.htm#TOC"
Expand Down
11 changes: 5 additions & 6 deletions src/libqhull_r/merge_r.c
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ void qh_appendmergeset(qhT *qh, facetT *facet, facetT *neighbor, mergeType merge
return;
}
if (!qh->facet_mergeset || !qh->degen_mergeset) {
qh_fprintf(qh, qh->ferr, 6403, "qhull internal error (qh_appendmergeset): expecting temp set defined for qh.facet_mergeset (0x%x) and qh.degen_mergeset (0x%x). Got NULL\n",
qh_fprintf(qh, qh->ferr, 6403, "qhull internal error (qh_appendmergeset): expecting temp set defined for qh.facet_mergeset (%p) and qh.degen_mergeset (%p). Got NULL\n",
qh->facet_mergeset, qh->degen_mergeset);
/* otherwise qh_setappend creates a new set that is not freed by qh_freebuild() */
qh_errexit(qh, qh_ERRqhull, NULL, NULL);
Expand Down Expand Up @@ -513,8 +513,7 @@ void qh_appendvertexmerge(qhT *qh, vertexT *vertex, vertexT *destination, mergeT
const char *mergename;

if (!qh->vertex_mergeset) {
qh_fprintf(qh, qh->ferr, 6387, "qhull internal error (qh_appendvertexmerge): expecting temp set defined for qh.vertex_mergeset (0x%x). Got NULL\n",
qh->vertex_mergeset);
qh_fprintf(qh, qh->ferr, 6387, "qhull internal error (qh_appendvertexmerge): expecting temp set defined for qh.vertex_mergeset. Got NULL\n");
/* otherwise qh_setappend creates a new set that is not freed by qh_freebuild() */
qh_errexit(qh, qh_ERRqhull, NULL, NULL);
}
Expand Down Expand Up @@ -1654,7 +1653,7 @@ void qh_forcedmerges(qhT *qh, boolT *wasmerge) {
void qh_freemergesets(qhT *qh) {

if (!qh->facet_mergeset || !qh->degen_mergeset || !qh->vertex_mergeset) {
qh_fprintf(qh, qh->ferr, 6388, "qhull internal error (qh_freemergesets): expecting mergesets. Got a NULL mergeset, qh.facet_mergeset (0x%x), qh.degen_mergeset (0x%x), qh.vertex_mergeset (0x%x)\n",
qh_fprintf(qh, qh->ferr, 6388, "qhull internal error (qh_freemergesets): expecting mergesets. Got a NULL mergeset, qh.facet_mergeset (%p), qh.degen_mergeset (%p), qh.vertex_mergeset (%p)\n",
qh->facet_mergeset, qh->degen_mergeset, qh->vertex_mergeset);
qh_errexit(qh, qh_ERRqhull, NULL, NULL);
}
Expand Down Expand Up @@ -2034,7 +2033,7 @@ ridgeT *qh_hashridge_find(qhT *qh, setT *hashtable, int hashsize, ridgeT *ridge,
void qh_initmergesets(qhT *qh /* qh.facet_mergeset,degen_mergeset,vertex_mergeset */) {

if (qh->facet_mergeset || qh->degen_mergeset || qh->vertex_mergeset) {
qh_fprintf(qh, qh->ferr, 6386, "qhull internal error (qh_initmergesets): expecting NULL mergesets. Got qh.facet_mergeset (0x%x), qh.degen_mergeset (0x%x), qh.vertex_mergeset (0x%x)\n",
qh_fprintf(qh, qh->ferr, 6386, "qhull internal error (qh_initmergesets): expecting NULL mergesets. Got qh.facet_mergeset (%p), qh.degen_mergeset (%p), qh.vertex_mergeset (%p)\n",
qh->facet_mergeset, qh->degen_mergeset, qh->vertex_mergeset);
qh_errexit(qh, qh_ERRqhull, NULL, NULL);
}
Expand Down Expand Up @@ -2304,7 +2303,7 @@ void qh_maybe_duplicateridge(qhT *qh, ridgeT *ridgeA) {
if (k == last) {
vertex= qh_findbest_ridgevertex(qh, ridge, &pinched, &dist);
trace2((qh, qh->ferr, 2069, "qh_maybe_duplicateridge: will merge v%d into v%d (dist %2.2g) due to duplicate ridges r%d/r%d with the same vertices. mergevertex set\n",
pinched->id, vertex->id, dist, ridgeA->id, ridge->id, ridgeA->top->id, ridgeA->bottom->id, ridge->top->id, ridge->bottom->id));
pinched->id, vertex->id, dist, ridgeA->id, ridge->id));
qh_appendvertexmerge(qh, pinched, vertex, MRGvertices, dist, ridgeA, ridge);
ridge->mergevertex= True; /* disables check for duplicate vertices in qh_checkfacet */
ridgeA->mergevertex= True;
Expand Down
5 changes: 3 additions & 2 deletions src/libqhull_r/poly2_r.c
Original file line number Diff line number Diff line change
Expand Up @@ -1145,7 +1145,7 @@ boolT qh_checklists(qhT *qh, facetT *facetlist) {
vertex->visitid= qh->vertex_visit;
if (vertex->previous != previousvertex) {
qh_fprintf(qh, qh->ferr, 6427, "qhull internal error (qh_checklists): expecting v%d.previous == v%d. Got v%d\n",
vertex->id, previousvertex, getid_(vertex->previous));
vertex->id, previousvertex->id, getid_(vertex->previous));
waserror= True;
errorvertex= vertex;
}
Expand Down Expand Up @@ -2280,7 +2280,8 @@ void qh_initialhull(qhT *qh, setT *vertices) {
zzinc_(Zdistcheck);
qh_distplane(qh, qh->interior_point, facet, &dist); /* duplicates qh_setfacetplane */
if (dist > qh->DISTround) { /* clearly flipped, due to axis-parallel facet or coplanar firstfacet */
trace1((qh, qh->ferr, 1031, "qh_initialhull: initial orientation incorrect, qh.interior_point is %2.2g from f%d. Either axis-parallel facet or coplanar firstfacet f%d. Force outside orientation of all facets\n"));
trace1((qh, qh->ferr, 1031, "qh_initialhull: initial orientation incorrect, qh.interior_point is %2.2g from f%d. Either axis-parallel facet or coplanar firstfacet f%d. Force outside orientation of all facets\n",
dist, facet->id, firstfacet->id));
FORALLfacets { /* reuse facet, then 'break' */
facet->flipped= False;
facet->toporient ^= (unsigned char)True;
Expand Down
2 changes: 1 addition & 1 deletion src/libqhullcpp/Qhull.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ initializeFeasiblePoint(int hulldim)
qh_errexit(qh_qh, qh_ERRmem, NULL, NULL);
}
if(feasible_point.size()!=static_cast<size_t>(hulldim)){
qh_fprintf(qh_qh, qh_qh->ferr, 6210, "qhull error: dimension of feasiblePoint should be %d. It is %u\n", hulldim, feasible_point.size());
qh_fprintf(qh_qh, qh_qh->ferr, 6210, "qhull error: dimension of feasiblePoint should be %d. It is %u\n", hulldim, (unsigned int)feasible_point.size());
qh_errexit(qh_qh, qh_ERRmem, NULL, NULL);
}
qh_qh->feasible_point= static_cast<coordT*>(qh_malloc(static_cast<size_t>(hulldim) * sizeof(coordT)));
Expand Down
Loading