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

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

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

Simon Goldschmidt
URL:
  <https://savannah.nongnu.org/bugs/?57565>

                 Summary: _IO, _IOR, _IOW macros expect sizeof() result to be
long type - not always true
                 Project: lwIP - A Lightweight TCP/IP stack
            Submitted by: vbrzeski
            Submitted on: Thu 09 Jan 2020 04:01:51 PM UTC
                Category: sockets/netconn
                Severity: 3 - Normal
              Item Group: Change Request
                  Status: None
                 Privacy: Public
             Assigned to: None
             Open/Closed: Open
         Discussion Lock: Any
         Planned Release: None
            lwIP version: git head

    _______________________________________________________

Details:

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.




    _______________________________________________________

Reply to this item at:

  <https://savannah.nongnu.org/bugs/?57565>

_______________________________________________
  Message sent via Savannah
  https://savannah.nongnu.org/


_______________________________________________
lwip-devel mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/lwip-devel
Reply | Threaded
Open this post in threaded view
|

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

Simon Goldschmidt
Follow-up Comment #1, bug #57565 (project lwip):

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

    _______________________________________________________

Reply to this item at:

  <https://savannah.nongnu.org/bugs/?57565>

_______________________________________________
  Message sent via Savannah
  https://savannah.nongnu.org/


_______________________________________________
lwip-devel mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/lwip-devel
Reply | Threaded
Open this post in threaded view
|

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

Simon Goldschmidt
Follow-up Comment #2, bug #57565 (project lwip):

[comment #1 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

    _______________________________________________________

Reply to this item at:

  <https://savannah.nongnu.org/bugs/?57565>

_______________________________________________
  Message sent via Savannah
  https://savannah.nongnu.org/


_______________________________________________
lwip-devel mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/lwip-devel
Reply | Threaded
Open this post in threaded view
|

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

Simon Goldschmidt
Follow-up Comment #3, bug #57565 (project lwip):


[comment #2 comment #2:]
> [comment #1 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



    _______________________________________________________

Reply to this item at:

  <https://savannah.nongnu.org/bugs/?57565>

_______________________________________________
  Message sent via Savannah
  https://savannah.nongnu.org/


_______________________________________________
lwip-devel mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/lwip-devel
Reply | Threaded
Open this post in threaded view
|

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

Simon Goldschmidt
Update of bug #57565 (project lwip):

                  Status:                    None => Fixed                  
             Assigned to:                    None => goldsimon              
             Open/Closed:                    Open => Closed                

    _______________________________________________________

Follow-up Comment #4:

> #define IOCPARM_MASK 0x7fUL

Did that.

    _______________________________________________________

Reply to this item at:

  <https://savannah.nongnu.org/bugs/?57565>

_______________________________________________
  Message sent via Savannah
  https://savannah.nongnu.org/


_______________________________________________
lwip-devel mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/lwip-devel