You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by ac...@apache.org on 2020/07/19 18:49:27 UTC

[incubator-nuttx] 02/07: libc: Typecast to avoid overflow in inet_addr for AVR

This is an automated email from the ASF dual-hosted git repository.

acassis pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git

commit 871613f271f028affbb2c71b307bd88daa9cf472
Author: Alan C. Assis <ac...@gmail.com>
AuthorDate: Sun Jul 19 15:25:47 2020 +0000

    libc: Typecast to avoid overflow in inet_addr for AVR
    
    Signed-off-by: Brennan Ashton <ba...@brennanashton.com>
---
 libs/libc/net/lib_inetaddr.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/libs/libc/net/lib_inetaddr.c b/libs/libc/net/lib_inetaddr.c
index e71ee8e..1b6db62 100644
--- a/libs/libc/net/lib_inetaddr.c
+++ b/libs/libc/net/lib_inetaddr.c
@@ -102,7 +102,7 @@ in_addr_t inet_addr(FAR const char *cp)
         {
           if ((a < 0x100) && (b < 0x1000000))
             {
-              result = (a << 24) | b;
+              result = (((uint32_t) a) << 24) | b;
             }
           break;
         }
@@ -111,7 +111,7 @@ in_addr_t inet_addr(FAR const char *cp)
         {
           if ((a < 0x100) && (b < 0x100) && (c < 0x10000))
             {
-              result = (a << 24) | (b << 16) | c;
+              result = (((uint32_t) a) << 24) | (((uint32_t) b) << 16) | c;
             }
           break;
         }
@@ -120,7 +120,8 @@ in_addr_t inet_addr(FAR const char *cp)
         {
           if ((a < 0x100) && (b < 0x100) && (c < 0x100) && (d < 0x100))
             {
-              result = (a << 24) | (b << 16) | (c << 8) | d;
+              result = (((uint32_t) a) << 24) | (((uint32_t) b) << 16) |
+                       (((uint32_t) c) << 8) | d;
             }
           break;
         }