Satisfied -fanalyzer under -DNDEBUG with local_assert
This commit is contained in:
parent
b7855adc6b
commit
b7f41cde4b
13
baked.c
13
baked.c
@ -34,10 +34,9 @@
|
|||||||
*
|
*
|
||||||
* TODO
|
* TODO
|
||||||
*
|
*
|
||||||
* 1. replace asserts with proper checks (maybe longjmp, however
|
* 1. somehow convince the compiler to do NULL checks before g_...
|
||||||
* this might be costly, and might not satify -fanalyzer)
|
* so that allocs can be minimized even further (maybe it should be volatile)
|
||||||
* 2. somehow convince the compiler to do NULL checks before g_...
|
* 2. support #!/bin/someshell
|
||||||
* so that allocs can be minimized even further (maybe volatile)
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
@ -73,6 +72,8 @@
|
|||||||
static const char * argv0;
|
static const char * argv0;
|
||||||
static char * g_filename = NULL, * g_sh = NULL, * g_all = NULL;
|
static char * g_filename = NULL, * g_sh = NULL, * g_all = NULL;
|
||||||
|
|
||||||
|
#define local_assert(expr, ret) do { assert(expr); return ret; } while(0)
|
||||||
|
|
||||||
static void
|
static void
|
||||||
_die(const char * fmt, ...)
|
_die(const char * fmt, ...)
|
||||||
{
|
{
|
||||||
@ -161,7 +162,7 @@ insert(const char * new, char * str, size_t offset, size_t shift)
|
|||||||
size_t max = strlen(str) + 1;
|
size_t max = strlen(str) + 1;
|
||||||
/* fprintf(stderr, "params '%s' '%s' %ld %ld\n", new, str, offset, shift); */
|
/* fprintf(stderr, "params '%s' '%s' %ld %ld\n", new, str, offset, shift); */
|
||||||
str = realloc(str, max + len);
|
str = realloc(str, max + len);
|
||||||
assert(str);
|
local_assert(str, NULL);
|
||||||
memmove(str + offset + len, str + offset + shift, max - offset - shift);
|
memmove(str + offset + len, str + offset + shift, max - offset - shift);
|
||||||
memcpy(str + offset, new, len);
|
memcpy(str + offset, new, len);
|
||||||
return str;
|
return str;
|
||||||
@ -172,7 +173,7 @@ expand(char * buf, size_t len)
|
|||||||
{
|
{
|
||||||
size_t i = 0;
|
size_t i = 0;
|
||||||
char * str = "";
|
char * str = "";
|
||||||
assert(buf);
|
local_assert(buf, NULL);
|
||||||
for (i = 0; i < len; ++i)
|
for (i = 0; i < len; ++i)
|
||||||
{
|
{
|
||||||
if (buf[i] == '\\')
|
if (buf[i] == '\\')
|
||||||
|
Loading…
Reference in New Issue
Block a user