buglwIP - A Lightweight TCP/IP stack - Bugs: bug #57565, _IO, _IOR, _IOW macros expect...

 
 

You are not allowed to post comments on this tracker with your current authentication level.

bug #57565: _IO, _IOR, _IOW macros expect sizeof() result to be long type - not always true

Submitted by:  Victor Brzeski <vbrzeski>
Submitted on:  Thu 09 Jan 2020 04:01:51 PM UTC  
 
Category:  sockets/netconn Severity:  3 - Normal
Item Group:  Change Request Status:  Fixed
Privacy:  Public Assigned to:  Simon Goldschmidt <goldsimon>
Open/Closed:  Closed Planned Release:  None
lwIP version:  git head

Fri 10 Jan 2020 07:47:05 PM UTC, comment #4: 

> #define IOCPARM_MASK 0x7fUL


Did that.

Simon Goldschmidt <goldsimon>
Project AdministratorIn charge of this item.
Fri 10 Jan 2020 04:56:42 PM UTC, comment #3: 

comment #2:

> comment #1:
> > So did you get compiler warnings without casting sizeof(t) to long? If so, could you copy them here?
>
> lwip\lwip-2.1.2\src\api\sockets.c(3848): warning C200: '<<': shift factor out of range, truncated
> unreachable code
>
> Compiler is Keil C166 v7.57


Simon,

I would like to propose a simpler solution. Just change:
#define IOCPARM_MASK 0x7fU
to
#define IOCPARM_MASK 0x7fUL

Victor Brzeski <vbrzeski>
Thu 09 Jan 2020 10:31:20 PM UTC, comment #2: 

comment #1:

> So did you get compiler warnings without casting sizeof(t) to long? If so, could you copy them here?


lwip\lwip-2.1.2\src\api\sockets.c(3848): warning C200: '<<': shift factor out of range, truncated
unreachable code

Compiler is Keil C166 v7.57

Victor Brzeski <vbrzeski>
Thu 09 Jan 2020 08:54:03 PM UTC, comment #1: 

So did you get compiler warnings without casting sizeof(t) to long? If so, could you copy them here?

Simon Goldschmidt <goldsimon>
Project AdministratorIn charge of this item.
Thu 09 Jan 2020 04:01:51 PM UTC, original submission:  

Hello,

The way the ioctls are designed are to assume the result of sizeof() is a long, where in my case it is not. The code below shows this:

#define _IO(x,y)        ((long)(IOC_VOID|((x)<<8)|(y)))

#define _IOR(x,y,t)     ((long)(IOC_OUT|((sizeof(t)&IOCPARM_MASK)<<16)|((x)<<8)|(y)))

#define _IOW(x,y,t)     ((long)(IOC_IN|((sizeof(t)&IOCPARM_MASK)<<16)|((x)<<8)|(y)))

I had this issue very early in the project and fixed it by simply casting the sizeof() intrinsic to a long.

#define _IO(x, y)     ((long)(IOC_VOID | ((x) << 8) | (y)))
#define _IOR(x, y, t) ((long)(IOC_OUT | (((long)sizeof(t) & IOCPARM_MASK) << 16) | ((x) << 8) | (y)))
#define _IOW(x, y, t) ((long)(IOC_IN | (((long)sizeof(t) & IOCPARM_MASK) << 16) | ((x) << 8) | (y)))

This should be adequate to fix my 16-bit problem, and shouldn't invoke any performance penalties as sizeof() resolves compile-time.

Kind regards,
Victor B.

Victor Brzeski <vbrzeski>

 

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by goldsimon (Posted a comment)
  • -email is unavailable- added by vbrzeski (Submitted the item)
  • -email is unavailable- added by vbrzeski
  •  

    Do you think this task is very important?
    If so, you can add your encouragement to it.
    This task has 0 encouragements so far.

    Only logged-in users can vote.

     

     

     

    Follow 4 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2020-01-10 goldsimon StatusNone => Fixed
        Assigned toNone => goldsimon
        Open/ClosedOpen => Closed
    2020-01-09 vbrzeski Carbon-Copy- => Added vbrzeski@slb.com

    Back to the top


    Powered by Savane 3.5