lwip-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[lwip-devel] [bug #51447] Sequence number comparisons invoke implementat


From: Ambroz Bizjak
Subject: [lwip-devel] [bug #51447] Sequence number comparisons invoke implementation-defined behavior
Date: Mon, 17 Jul 2017 15:52:49 -0400 (EDT)
User-agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36

Follow-up Comment #10, bug #51447 (project lwip):

@Simon, all can be expressed in terms of LT as I have shown in the first post.
Here is passing test code showing my macros behave the same as current ones in
edge cases (a=b-1, a=b, a=b+1).



#include <assert.h>
#include <stdint.h>

typedef uint32_t u32_t;
typedef int32_t s32_t;

#define TCP_SEQ_LT(a,b) ((u32_t)((u32_t)(a) - (u32_t)(b)) >= 0x80000000u) 
#define TCP_SEQ_LEQ(a,b) (!(TCP_SEQ_LT(b,a))) 
#define TCP_SEQ_GT(a,b) TCP_SEQ_LT(b,a) 
#define TCP_SEQ_GEQ(a,b) TCP_SEQ_LEQ(b,a)

#define TCP_SEQ_LT_OLD(a,b)     ((s32_t)((u32_t)(a) - (u32_t)(b)) < 0)
#define TCP_SEQ_LEQ_OLD(a,b)    ((s32_t)((u32_t)(a) - (u32_t)(b)) <= 0)
#define TCP_SEQ_GT_OLD(a,b)     ((s32_t)((u32_t)(a) - (u32_t)(b)) > 0)
#define TCP_SEQ_GEQ_OLD(a,b)    ((s32_t)((u32_t)(a) - (u32_t)(b)) >= 0)

int main()
{
    assert(TCP_SEQ_LT    (5, 6));
    assert(TCP_SEQ_LT_OLD(5, 6));
    
    assert(!TCP_SEQ_LT    (6, 6));
    assert(!TCP_SEQ_LT_OLD(6, 6));
    
    assert(!TCP_SEQ_LT    (7, 6));
    assert(!TCP_SEQ_LT_OLD(7, 6));
    
    
    assert(TCP_SEQ_LEQ    (5, 6));
    assert(TCP_SEQ_LEQ_OLD(5, 6));
    
    assert(TCP_SEQ_LEQ    (6, 6));
    assert(TCP_SEQ_LEQ_OLD(6, 6));
    
    assert(!TCP_SEQ_LEQ    (7, 6));
    assert(!TCP_SEQ_LEQ_OLD(7, 6));
    
    
    assert(!TCP_SEQ_GT    (5, 6));
    assert(!TCP_SEQ_GT_OLD(5, 6));
    
    assert(!TCP_SEQ_GT    (6, 6));
    assert(!TCP_SEQ_GT_OLD(6, 6));
    
    assert(TCP_SEQ_GT    (7, 6));
    assert(TCP_SEQ_GT_OLD(7, 6));
    
    
    assert(!TCP_SEQ_GEQ    (5, 6));
    assert(!TCP_SEQ_GEQ_OLD(5, 6));
    
    assert(TCP_SEQ_GEQ    (6, 6));
    assert(TCP_SEQ_GEQ_OLD(6, 6));
    
    assert(TCP_SEQ_GEQ    (7, 6));
    assert(TCP_SEQ_GEQ_OLD(7, 6));
    
    
    // Sanity check asserts are enabled
    assert(0);
    
    return 0;
}


    _______________________________________________________

Reply to this item at:

  <http://savannah.nongnu.org/bugs/?51447>

_______________________________________________
  Message sent via/by Savannah
  http://savannah.nongnu.org/




reply via email to

[Prev in Thread] Current Thread [Next in Thread]