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

Submitter:  Victor Brzeski <vbrzeski>
Submitted:  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:  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>
Group administrator
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>
Group administrator
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>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

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
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

     

    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 -email is unavailable-

    Back to the top

    Powered by Savane 3.13-02a9.
    Corresponding source code