Loading...
Searching...
No Matches
omError.c
Go to the documentation of this file.
/*******************************************************************
* File: omError.c
* Purpose: implementation of Error handling routines
* Author: obachman (Olaf Bachmann)
* Created: 11/99
*******************************************************************/
#include <stdarg.h>
#include "omalloc.h"
#ifdef HAVE_OMALLOC
omError_t om_ErrorStatus = omError_NoError;
omError_t om_InternalErrorStatus = omError_NoError;
struct omErrorString_s
{
omError_t error;
char* s_error;
char* string;
};
/* strings describing omErrors */
static const struct omErrorString_s om_ErrorStrings[] =
{
{omError_NoError, "omError_NoError", "no error"},
{omError_Unknown, "omError_Unknown", "unknown error" },
{omError_MemoryCorrupted, "omError_MemoryCorrupted", "memory corrupted"},
{omError_InternalBug, "omError_InternalBug", "internal omalloc bug"},
{omError_NullAddr, "omError_NullAddr", "addr is NULL"},
{omError_InvalidRangeAddr, "omError_InvalidRangeAddr", "addr not in valid range"},
{omError_FalseAddr, "omError_FalseAddr", "addr not as returned by omalloc"},
{omError_FalseAddrOrMemoryCorrupted, "omError_FalseAddrOrMemoryCorrupted", "addr not as returned by omalloc or memory corrupted", },
{omError_WrongSize, "omError_WrongSize", "wrong size specification of addr"},
{omError_FreedAddr, "omError_FreedAddr", "addr had previously been freed"},
{omError_FreedAddrOrMemoryCorrupted, "omError_FreedAddrOrMemoryCorrupted", "addr had previously been freed or memory corrupted"},
{omError_WrongBin, "omError_WrongBin", "addr is not from given Bin"},
{omError_UnknownBin, "omError_UnknownBin", "given Bin is unknown"},
{omError_NotBinAddr, "omError_NotBinAddr", "addr is not a BinAddr"},
{omError_UnalignedAddr, "omError_UnalignedAddr", "addr is unaligned"},
{omError_NullSizeAlloc, "omError_NullSizeAlloc", "alloc of size 0"},
{omError_ListCycleError, "omError_ListCycleError", "list has cycles"},
{omError_SortedListError, "omError_SortedListError", "sorted list is unsorted"},
{omError_KeptAddrListCorrupted, "omError_KeptAddrListCorrupted", "list of kept addresses are corrupted"},
{omError_FrontPattern, "omError_FrontPattern", "written to front of addr"},
{omError_BackPattern, "omError_BackPattern", "written after end of addr"},
{omError_FreePattern, "omError_FreePattern", "written into freed memory"},
{omError_NotString, "omError_NotString", "string not null terminated"},
{omError_StickyBin, "omError_StickyBin", "wrong handling of sticky bins"},
{omError_MaxError, NULL} /* this needs to be the last entry */
};
const char* omError2String(omError_t error)
{
int i = 0;
while (! (om_ErrorStrings[i].string == NULL && om_ErrorStrings[i].error == omError_MaxError))
{
if (om_ErrorStrings[i].error == error) return om_ErrorStrings[i].string;
i++;
}
return "undocumented error";
}
const char* omError2Serror(omError_t error)
{
int i = 0;
while (! (om_ErrorStrings[i].string == NULL && om_ErrorStrings[i].error == omError_MaxError))
{
if (om_ErrorStrings[i].error == error) return om_ErrorStrings[i].s_error;
i++;
}
return "omError_UnKnown";
}
#ifndef OM_NDEBUG
int om_CallErrorHook = 1;
#endif
omError_t omReportError(omError_t error, omError_t report_error, OM_FLR_DECL,
const char* fmt, ...)
{
int max_check, max_track;
if (report_error == omError_MaxError) return error;
/* reset MaxTrack and MaxCheck to prevent infinite loop, in case
printf allocates memory */
max_check = om_Opts.MaxCheck;
max_track = om_Opts.MaxTrack;
om_Opts.MaxCheck = 0;
om_Opts.MaxTrack = 0;
om_InternalErrorStatus = error;
om_ErrorStatus = (report_error == omError_NoError ? error : report_error);
if (om_Opts.HowToReportErrors && om_ErrorStatus != omError_NoError)
{
/* to avoid spurious error msg in 64 bit mode*/
if (om_ErrorStatus == omError_StickyBin) return error;
fprintf(stderr, "***%s: %s", omError2Serror(om_ErrorStatus), omError2String(om_ErrorStatus));
#ifdef OM_INTERNAL_DEBUG
if (om_ErrorStatus != error)
fprintf(stderr, "\n___%s: %s", omError2Serror(error), omError2String(error));
#endif
if (om_Opts.HowToReportErrors > 2 && fmt != NULL && *fmt != '\0')
{
va_list ap;
va_start(ap, fmt);
fputs( ": ",stderr);
vfprintf(stderr, fmt, ap);
va_end(ap);
}
if (om_Opts.HowToReportErrors > 1)
{
#ifndef OM_NDEBUG
fputs("\n occurred at: ",stderr);
if (! _omPrintCurrentBackTrace(stderr, OM_FLR_VAL))
fputs(" ??",stderr);
#endif
}
fputc('\n',stderr);
fflush(stderr);
}
if (om_CallErrorHook)
om_Opts.ErrorHook();
om_Opts.MaxCheck = max_check;
om_Opts.MaxTrack = max_track;
return error;
}
/* this is a dummy function and used as default for om_Opts.ErrorHook */
extern void omErrorBreak()
{}
#endif
i
int i
Definition cfEzgcd.cc:132
error
#define error(a)
Definition mpr_numeric.cc:966
ap
Definition ap.h:40
om_ErrorStatus
omError_t om_ErrorStatus
Definition omError.c:13
omError2String
const char * omError2String(omError_t error)
Definition omError.c:54
omErrorString_s::s_error
char * s_error
Definition omError.c:19
om_ErrorStrings
static const struct omErrorString_s om_ErrorStrings[]
Definition omError.c:24
omErrorString_s::error
omError_t error
Definition omError.c:18
omError2Serror
const char * omError2Serror(omError_t error)
Definition omError.c:65
om_CallErrorHook
int om_CallErrorHook
Definition omError.c:77
omErrorBreak
void omErrorBreak()
Definition omError.c:137
omReportError
omError_t omReportError(omError_t error, omError_t report_error, OM_FLR_DECL, const char *fmt,...)
Definition omError.c:80
omErrorString_s::string
char * string
Definition omError.c:20
om_InternalErrorStatus
omError_t om_InternalErrorStatus
Definition omError.c:14
omErrorString_s
Definition omError.c:17
omError_WrongSize
@ omError_WrongSize
Definition omError.h:26
omError_ListCycleError
@ omError_ListCycleError
Definition omError.h:34
omError_BackPattern
@ omError_BackPattern
Definition omError.h:38
omError_NullAddr
@ omError_NullAddr
Definition omError.h:22
omError_NullSizeAlloc
@ omError_NullSizeAlloc
Definition omError.h:33
omError_MaxError
@ omError_MaxError
Definition omError.h:42
omError_FrontPattern
@ omError_FrontPattern
Definition omError.h:39
omError_UnalignedAddr
@ omError_UnalignedAddr
Definition omError.h:32
omError_MemoryCorrupted
@ omError_MemoryCorrupted
Definition omError.h:21
omError_FreedAddr
@ omError_FreedAddr
Definition omError.h:27
omError_UnknownBin
@ omError_UnknownBin
Definition omError.h:30
omError_FreedAddrOrMemoryCorrupted
@ omError_FreedAddrOrMemoryCorrupted
Definition omError.h:28
omError_NotString
@ omError_NotString
Definition omError.h:40
omError_SortedListError
@ omError_SortedListError
Definition omError.h:35
omError_KeptAddrListCorrupted
@ omError_KeptAddrListCorrupted
Definition omError.h:36
omError_InternalBug
@ omError_InternalBug
Definition omError.h:20
omError_NotBinAddr
@ omError_NotBinAddr
Definition omError.h:31
omError_InvalidRangeAddr
@ omError_InvalidRangeAddr
Definition omError.h:23
omError_FalseAddr
@ omError_FalseAddr
Definition omError.h:24
omError_WrongBin
@ omError_WrongBin
Definition omError.h:29
omError_NoError
@ omError_NoError
Definition omError.h:18
omError_Unknown
@ omError_Unknown
Definition omError.h:19
omError_StickyBin
@ omError_StickyBin
Definition omError.h:41
omError_FreePattern
@ omError_FreePattern
Definition omError.h:37
omError_FalseAddrOrMemoryCorrupted
@ omError_FalseAddrOrMemoryCorrupted
Definition omError.h:25
omError_t
enum omError_e omError_t
Definition omError.h:44
NULL
#define NULL
Definition omList.c:12
om_Opts
omOpts_t om_Opts
Definition omOpts.c:13
_omPrintCurrentBackTrace
int _omPrintCurrentBackTrace(FILE *fd, OM_FLR_DECL)
Definition omRet2Info.c:271
omalloc.h