From df4e24ddeb9743a49d6338ffb542eef3f625dbc8 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Wed, 22 Apr 2015 07:35:35 -0600 Subject: [PATCH] include/assert.h: Wrap definitions of assertion macros in do while. Suggested by orbitalfox --- include/assert.h | 38 +++++++++++++++++++++++++++++++++----- 1 file changed, 33 insertions(+), 5 deletions(-) diff --git a/include/assert.h b/include/assert.h index 8934d4d55d2..bb6948ab53c 100644 --- a/include/assert.h +++ b/include/assert.h @@ -1,7 +1,7 @@ /**************************************************************************** * include/assert.h * - * Copyright (C) 2007-2009, 2011-2013 Gregory Nutt. All rights reserved. + * Copyright (C) 2007-2009, 2011-2013, 2015 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -58,10 +58,24 @@ #ifdef CONFIG_HAVE_FILENAME # define ASSERT(f) \ - { if (!(f)) up_assert((const uint8_t *)__FILE__, (int)__LINE__); } + do \ + { \ + if (!(f)) \ + { \ + up_assert((const uint8_t *)__FILE__, (int)__LINE__); \ + } \ + } \ + while (0) # define VERIFY(f) \ - { if ((f) < 0) up_assert((const uint8_t *)__FILE__, (int)__LINE__); } + do \ + { \ + if ((f) < 0) \ + { \ + up_assert((const uint8_t *)__FILE__, (int)__LINE__); \ + } \ + } \ + while (0) # define PANIC() \ up_assert((const uint8_t *)__FILE__, (int)__LINE__) @@ -69,10 +83,24 @@ # ifdef CONFIG_DEBUG # define DEBUGASSERT(f) \ - { if (!(f)) up_assert((const uint8_t *)__FILE__, (int)__LINE__); } + do \ + { \ + if (!(f)) \ + { \ + up_assert((const uint8_t *)__FILE__, (int)__LINE__); \ + } \ + } \ + while (0) # define DEBUGVERIFY(f) \ - { if ((f) < 0) up_assert((const uint8_t *)__FILE__, (int)__LINE__); } + do \ + { \ + if ((f) < 0) \ + { \ + up_assert((const uint8_t *)__FILE__, (int)__LINE__); \ + } \ + } \ + while (0) # define DEBUGPANIC() \ up_assert((const uint8_t *)__FILE__, (int)__LINE__)