linux-usb-gadgets / libusbgx

C library encapsulating the Linux kernel USB gadget configfs userspace API functionality
GNU General Public License v2.0
216 stars 72 forks source link

uvc: fix unsigned nmb to int #63

Closed mgrzeschik closed 3 years ago

mgrzeschik commented 3 years ago

Since snprintf returns int not unsigned we change the type of nmb.

Signed-off-by: Michael Grzeschik m.grzeschik@pengutronix.de

pabs3 commented 3 years ago

This brings back the warnings about comparing signed and unsigned ints.

I'm not sure what the correct way of handling this is TBH.

-- bye, pabs

https://bonedaddy.net/pabs3/

mgrzeschik commented 3 years ago

I would merge it. So at least its equally wrong to the rest of the libusbgx stack. As second step we could add an patch over the whole tree, that fixes the comparison between sizeof and int by casting one of the sides.

pabs3 commented 3 years ago

OK, sounds good.

This RedHat blog post covers printf truncation:

https://developers.redhat.com/blog/2018/05/24/detecting-string-truncation-with-gcc-8

It suggests these options:

  1. snprintf(NULL); malloc(); snprintf();
  2. open_memstream(); fprintf(); fclose();
  3. asprintf(); (GNU/BSD only)
  4. snprintf(ptr); if(ret<0 || (size_t)ret>sizeof(ptr)) return error;

I'll leave it to you to decide which of those is best, but personally I would choose 3 > 4 > 1 > 2.

-- bye, pabs

https://bonedaddy.net/pabs3/

mgrzeschik commented 3 years ago

I will now look into the blogpost and cook a patch.