Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

#351 sizeof should be strlen?

trunk
closed-invalid
Rich Mattes
player (137)
5
2011-02-16
2011-02-15
Jayen Ashar
No

Hi, on line 90 of device.c (http://playerstage.svn.sourceforge.net/viewvc/playerstage/code/player/trunk/client_libs/libplayerc/device.c?annotate=9036 ), I believe the sizeof should be strlen, as that parameter is used in strncpy on line 1082 of client.c (http://playerstage.svn.sourceforge.net/viewvc/playerstage/code/player/trunk/client_libs/libplayerc/client.c?annotate=9036 ).

Discussion

  • Chris
    Chris
    2011-02-15

    I'm pretty sure that it is correct as it is. strlen would be wrong as in playerc_client_subscribe the drivername passed is actually getting written to, len here is indicating the maximum size of the array getting passed in. strlen at this point would be 0 as the drivername that the sizeof is performed on is all NULLs at this point. Possibly for efficiency's sake strlen(resp->drivername) + 1 should be used instead - but if this only happens on subscribe then the overhead either way is pretty low

    1055 int playerc_client_subscribe(playerc_client_t *client, int code, int index,
    1056 int access, char *drivername, size_t len)

     
  • Jayen Ashar
    Jayen Ashar
    2011-02-15

    so i think then, that sizeof and strlen are both wrong. that argument should be the amount of space allocated to device->drivername, in case less is allocated than the length of resp->driver_name.
    ...
    nevermind. i thought devicename was a char *, not a char[], so i guess sizeof should work. i was seeing warnings in valgrind about that strncpy call and jumped to the wrong conclusion. perhaps resp->driver_name is not null-terminated is my issue.

     
  • Rich Mattes
    Rich Mattes
    2011-02-16

    Closing this bug for now. Please re-open or file a new bug if you find another issue. Thanks.

     
  • Rich Mattes
    Rich Mattes
    2011-02-16

    • assigned_to: inspectorg --> jpgr87
    • labels: 429378 --> player
    • status: open --> closed-invalid