From: thiery Date: Wed, 16 Feb 2011 17:14:57 +0000 (+0000) Subject: Evaluating the expression of xbt_assert must not have side effects. X-Git-Tag: v3.6_beta2~293 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/91715e2f198242d378e33453014dd004fcf9f47e Evaluating the expression of xbt_assert must not have side effects. The xbt_assert macros are disabled at compile time when NDEBUG is set. There are a lot of other faulty xbt_assert calls, I haven't finished to fix them. git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@9644 48e7efb5-ca39-0410-a469-dd3cf9ba447f --- diff --git a/examples/msg/icomms/peer2.c b/examples/msg/icomms/peer2.c index 0d3fb0a4a0..7f60c2cbe0 100644 --- a/examples/msg/icomms/peer2.c +++ b/examples/msg/icomms/peer2.c @@ -66,8 +66,8 @@ int receiver(int argc, char *argv[]) int id = -1; char mailbox[80]; msg_comm_t res_irecv; - xbt_assert1(sscanf(argv[1], "%d", &id), - "Invalid argument %s\n", argv[1]); + int read = sscanf(argv[1], "%d", &id) + xbt_assert1(read, "Invalid argument %s\n", argv[1]); MSG_process_sleep(10); sprintf(mailbox, "receiver-%d", id); while (1) { diff --git a/examples/msg/icomms/peer3.c b/examples/msg/icomms/peer3.c index a1398646eb..8b22f55b15 100644 --- a/examples/msg/icomms/peer3.c +++ b/examples/msg/icomms/peer3.c @@ -64,11 +64,12 @@ int sender(int argc, char *argv[]) sprintf(mailbox, "finalize"); msg_comm_t res_irecv; + MSG_error_t res_wait; for (i = 0; i < receivers_count; i++) { task = NULL; res_irecv = MSG_task_irecv(&(task), mailbox); - xbt_assert0(MSG_comm_wait(res_irecv, -1) == MSG_OK, - "MSG_comm_wait failed"); + res_wait = MSG_comm_wait(res_irecv, -1); + xbt_assert0(res == MSG_OK, "MSG_comm_wait failed"); MSG_comm_destroy(res_irecv); MSG_task_destroy(task); } @@ -87,8 +88,8 @@ int receiver(int argc, char *argv[]) int tasks = atof(argv[2]); m_task_t *task = xbt_new(m_task_t, tasks); - xbt_assert1(sscanf(argv[1], "%d", &id), - "Invalid argument %s\n", argv[1]); + int read = sscanf(argv[1], "%d", &id); + xbt_assert1(read, "Invalid argument %s\n", argv[1]); sprintf(mailbox, "receiver-%d", id); MSG_process_sleep(10); msg_comm_t res_irecv; diff --git a/examples/msg/masterslave/masterslave_forwarder.c b/examples/msg/masterslave/masterslave_forwarder.c index 312a922b39..4622644a05 100644 --- a/examples/msg/masterslave/masterslave_forwarder.c +++ b/examples/msg/masterslave/masterslave_forwarder.c @@ -39,12 +39,12 @@ int master(int argc, char *argv[]) int i; - xbt_assert1(sscanf(argv[1], "%d", &number_of_tasks), - "Invalid argument %s\n", argv[1]); - xbt_assert1(sscanf(argv[2], "%lg", &task_comp_size), - "Invalid argument %s\n", argv[2]); - xbt_assert1(sscanf(argv[3], "%lg", &task_comm_size), - "Invalid argument %s\n", argv[3]); + int res = sscanf(argv[1], "%d", &number_of_tasks); + xbt_assert1("Invalid argument %s\n", argv[1]); + res = sscanf(argv[2], "%lg", &task_comp_size); + xbt_assert1(res, "Invalid argument %s\n", argv[2]); + res = sscanf(argv[3], "%lg", &task_comm_size); + xbt_assert1(res, "Invalid argument %s\n", argv[3]); { /* Task creation */ char sprintf_buffer[64]; diff --git a/examples/msg/priority/priority.c b/examples/msg/priority/priority.c index 30ec3456a7..7075eb9457 100644 --- a/examples/msg/priority/priority.c +++ b/examples/msg/priority/priority.c @@ -20,11 +20,10 @@ static int test(int argc, char *argv[]) double priority = 1.0; m_task_t task = NULL; - - xbt_assert1(sscanf(argv[1], "%lg", &computation_amount), - "Invalid argument %s\n", argv[1]); - xbt_assert1(sscanf(argv[2], "%lg", &priority), - "Invalid argument %s\n", argv[2]); + int res = sscanf(argv[1], "%lg", &computation_amount); + xbt_assert1(res, "Invalid argument %s\n", argv[1]); + res = sscanf(argv[2], "%lg", &priority); + xbt_assert1(res, "Invalid argument %s\n", argv[2]); INFO2("Hello! Running a task of size %g with priority %g", computation_amount, priority); diff --git a/include/xbt/asserts.h b/include/xbt/asserts.h index 18fced6643..431ed94900 100644 --- a/include/xbt/asserts.h +++ b/include/xbt/asserts.h @@ -19,8 +19,12 @@ SG_BEGIN_DECL() * @addtogroup XBT_error * @brief Those are the SimGrid version of the good ol' assert macro. * - * You can pass them a format message and arguments, just as if it where a printf. + * You can pass them a format message and arguments, just as if it where a + * printf. * It is converted to a CRITICALn logging request. + * Be careful: the boolean expression that you want to test should not have + * side effects, because assertions are disabled at compile time if NDEBUG + * is set. * * @{ */