Skip to content

Commit

Permalink
fix #461
Browse files Browse the repository at this point in the history
  • Loading branch information
balos1 committed Apr 25, 2024
1 parent 1d61bdd commit de6151f
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 23 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ for more details.

Added support for Kokkos Kernels v4.

Fixed a bug that caused error messages to be cut off in some cases. Ref. #461.

## Changes to SUNDIALS in release v7.0.0

### Major Feature
Expand Down
3 changes: 3 additions & 0 deletions doc/shared/RecentChanges.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,6 @@ Fixed a bug where :c:func:`MRIStepEvolve` would not handle a recoverable error
produced from evolving the inner stepper.

Added support for Kokkos Kernels v4.

Fixed a bug that caused error messages to be cut off in some cases. Ref.
`#461 <https://github.com/LLNL/sundials/issues/461>`_.
10 changes: 7 additions & 3 deletions src/arkode/arkode.c
Original file line number Diff line number Diff line change
Expand Up @@ -3325,15 +3325,20 @@ int arkAccessHAdaptMem(void* arkode_mem, const char* fname, ARKodeMem* ark_mem,
void arkProcessError(ARKodeMem ark_mem, int error_code, int line,
const char* func, const char* file, const char* msgfmt, ...)
{
/* Initialize the argument pointer variable
/* We initialize the argument pointer variable before each time before calling vsnprintf to avoid undefined behavior
(msgfmt is the last required argument to arkProcessError) */
va_list ap;
va_start(ap, msgfmt);

/* Compose the message */
va_start(ap, msgfmt);
size_t msglen = vsnprintf(NULL, 0, msgfmt, ap) + 1;
va_end(ap);

char* msg = (char*)malloc(msglen);

va_start(ap, msgfmt);
vsnprintf(msg, msglen, msgfmt, ap);
va_end(ap);

do {
if (ark_mem == NULL)
Expand Down Expand Up @@ -3362,7 +3367,6 @@ void arkProcessError(ARKodeMem ark_mem, int error_code, int line,
while (0);

/* Finalize argument processing */
va_end(ap);
free(msg);

return;
Expand Down
11 changes: 7 additions & 4 deletions src/cvode/cvode.c
Original file line number Diff line number Diff line change
Expand Up @@ -4824,15 +4824,20 @@ static int cvEwtSetSV(CVodeMem cv_mem, N_Vector ycur, N_Vector weight)
void cvProcessError(CVodeMem cv_mem, int error_code, int line, const char* func,
const char* file, const char* msgfmt, ...)
{
/* Initialize the argument pointer variable
/* We initialize the argument pointer variable before each time before calling vsnprintf to avoid undefined behavior
(msgfmt is the last required argument to cvProcessError) */
va_list ap;
va_start(ap, msgfmt);

/* Compose the message */
va_start(ap, msgfmt);
size_t msglen = vsnprintf(NULL, 0, msgfmt, ap) + 1;
va_end(ap);

char* msg = (char*)malloc(msglen);

va_start(ap, msgfmt);
vsnprintf(msg, msglen, msgfmt, ap);
va_end(ap);

do {
if (cv_mem == NULL)
Expand Down Expand Up @@ -4860,8 +4865,6 @@ void cvProcessError(CVodeMem cv_mem, int error_code, int line, const char* func,
}
while (0);

/* Finalize argument processing */
va_end(ap);
free(msg);

return;
Expand Down
11 changes: 7 additions & 4 deletions src/cvodes/cvodes.c
Original file line number Diff line number Diff line change
Expand Up @@ -9908,15 +9908,20 @@ static int cvQuadSensRhs1InternalDQ(CVodeMem cv_mem, int is, sunrealtype t,
void cvProcessError(CVodeMem cv_mem, int error_code, int line, const char* func,
const char* file, const char* msgfmt, ...)
{
/* Initialize the argument pointer variable
/* We initialize the argument pointer variable before each time before calling vsnprintf to avoid undefined behavior
(msgfmt is the last required argument to cvProcessError) */
va_list ap;
va_start(ap, msgfmt);

/* Compose the message */
va_start(ap, msgfmt);
size_t msglen = vsnprintf(NULL, 0, msgfmt, ap) + 1;
va_end(ap);

char* msg = (char*)malloc(msglen);

va_start(ap, msgfmt);
vsnprintf(msg, msglen, msgfmt, ap);
va_end(ap);

do {
if (cv_mem == NULL)
Expand Down Expand Up @@ -9944,8 +9949,6 @@ void cvProcessError(CVodeMem cv_mem, int error_code, int line, const char* func,
}
while (0);

/* Finalize argument processing */
va_end(ap);
free(msg);

return;
Expand Down
11 changes: 7 additions & 4 deletions src/ida/ida.c
Original file line number Diff line number Diff line change
Expand Up @@ -3992,15 +3992,20 @@ static int IDARootfind(IDAMem IDA_mem)
void IDAProcessError(IDAMem IDA_mem, int error_code, int line, const char* func,
const char* file, const char* msgfmt, ...)
{
/* Initialize the argument pointer variable
/* We initialize the argument pointer variable before each time before calling vsnprintf to avoid undefined behavior
(msgfmt is the last required argument to IDAProcessError) */
va_list ap;
va_start(ap, msgfmt);

/* Compose the message */
va_start(ap, msgfmt);
size_t msglen = vsnprintf(NULL, 0, msgfmt, ap) + 1;
va_end(ap);

char* msg = (char*)malloc(msglen);

va_start(ap, msgfmt);
vsnprintf(msg, msglen, msgfmt, ap);
va_end(ap);

do {
if (IDA_mem == NULL)
Expand Down Expand Up @@ -4028,8 +4033,6 @@ void IDAProcessError(IDAMem IDA_mem, int error_code, int line, const char* func,
}
while (0);

/* Finalize argument processing */
va_end(ap);
free(msg);

return;
Expand Down
11 changes: 7 additions & 4 deletions src/idas/idas.c
Original file line number Diff line number Diff line change
Expand Up @@ -8756,15 +8756,20 @@ static int IDAQuadSensRhs1InternalDQ(IDAMem IDA_mem, int is, sunrealtype t,
void IDAProcessError(IDAMem IDA_mem, int error_code, int line, const char* func,
const char* file, const char* msgfmt, ...)
{
/* Initialize the argument pointer variable
/* We initialize the argument pointer variable before each time before calling vsnprintf to avoid undefined behavior
(msgfmt is the last required argument to IDAProcessError) */
va_list ap;
va_start(ap, msgfmt);

/* Compose the message */
va_start(ap, msgfmt);
size_t msglen = vsnprintf(NULL, 0, msgfmt, ap) + 1;
va_end(ap);

char* msg = (char*)malloc(msglen);

va_start(ap, msgfmt);
vsnprintf(msg, msglen, msgfmt, ap);
va_end(ap);

do {
if (IDA_mem == NULL)
Expand Down Expand Up @@ -8792,8 +8797,6 @@ void IDAProcessError(IDAMem IDA_mem, int error_code, int line, const char* func,
}
while (0);

/* Finalize argument processing */
va_end(ap);
free(msg);

return;
Expand Down
11 changes: 7 additions & 4 deletions src/kinsol/kinsol.c
Original file line number Diff line number Diff line change
Expand Up @@ -2563,15 +2563,20 @@ void KINPrintInfo(KINMem kin_mem, int info_code, const char* module,
void KINProcessError(KINMem kin_mem, int error_code, int line, const char* func,
const char* file, const char* msgfmt, ...)
{
/* Initialize the argument pointer variable
/* We initialize the argument pointer variable before each time before calling vsnprintf to avoid undefined behavior
(msgfmt is the last required argument to KINProcessError) */
va_list ap;
va_start(ap, msgfmt);

/* Compose the message */
va_start(ap, msgfmt);
size_t msglen = vsnprintf(NULL, 0, msgfmt, ap) + 1;
va_end(ap);

char* msg = (char*)malloc(msglen);

va_start(ap, msgfmt);
vsnprintf(msg, msglen, msgfmt, ap);
va_end(ap);

do {
if (kin_mem == NULL)
Expand Down Expand Up @@ -2599,8 +2604,6 @@ void KINProcessError(KINMem kin_mem, int error_code, int line, const char* func,
}
while (0);

/* Finalize argument processing */
va_end(ap);
free(msg);

return;
Expand Down

0 comments on commit de6151f

Please sign in to comment.