DPDK patches and discussions
 help / color / mirror / Atom feed
From: Julien Cretin <julien.cretin@trust-in-soft.com>
To: <dev@dpdk.org>
Subject: [dpdk-dev] [PATCH 1/3] app/testpmd: fix minor signed overflow in a constant
Date: Mon, 12 May 2014 17:35:09 +0200	[thread overview]
Message-ID: <1399908911-18829-2-git-send-email-julien.cretin@trust-in-soft.com> (raw)
In-Reply-To: <1399908911-18829-1-git-send-email-julien.cretin@trust-in-soft.com>

The expression (192 << 24) has an undefined behavior since:
- the integer constant 192 has type int, and
- 192 x 2^24 is not representable as an int.

Suffixing 192 with U defines a behavior since:
- the integer constant 192U has type unsigned int, and
- the value of (192U << 24) is defined as
  (192 x 2^24) % (UINT_MAX + 1)

This minor bug was found using TrustInSoft Analyzer.

Signed-off-by: Julien Cretin <julien.cretin@trust-in-soft.com>
---
 app/test-pmd/txonly.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/app/test-pmd/txonly.c b/app/test-pmd/txonly.c
index 1cf2574..5bbd34f 100644
--- a/app/test-pmd/txonly.c
+++ b/app/test-pmd/txonly.c
@@ -76,8 +76,8 @@
 #define UDP_SRC_PORT 1024
 #define UDP_DST_PORT 1024
 
-#define IP_SRC_ADDR ((192 << 24) | (168 << 16) | (0 << 8) | 1)
-#define IP_DST_ADDR ((192 << 24) | (168 << 16) | (0 << 8) | 2)
+#define IP_SRC_ADDR ((192U << 24) | (168 << 16) | (0 << 8) | 1)
+#define IP_DST_ADDR ((192U << 24) | (168 << 16) | (0 << 8) | 2)
 
 #define IP_DEFTTL  64   /* from RFC 1340. */
 #define IP_VERSION 0x40
-- 
1.9.1

  reply	other threads:[~2014-05-12 15:35 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-05-12 15:35 [dpdk-dev] [PATCH 0/3] Various patches Julien Cretin
2014-05-12 15:35 ` Julien Cretin [this message]
2014-05-12 15:35 ` [dpdk-dev] [PATCH 2/3] mem: remove redundant check in optimize_object_size Julien Cretin
2014-05-12 15:35 ` [dpdk-dev] [PATCH 3/3] app/testpmd: fix incompatible sign for printf arguments Julien Cretin
2014-05-14  9:26 ` [dpdk-dev] [PATCH 0/3] Various patches Thomas Monjalon

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1399908911-18829-2-git-send-email-julien.cretin@trust-in-soft.com \
    --to=julien.cretin@trust-in-soft.com \
    --cc=dev@dpdk.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).