Skip to content

Commit

Permalink
HACK windows string length thing
Browse files Browse the repository at this point in the history
This might address the following build warning/error:

```
D:/a/libserialport/libserialport/windows.c: In function 'get_port_details':
D:/a/libserialport/libserialport/windows.c:457:83: error: '%s' directive output may be truncated writing up to 31 bytes into a region of size between 20 and 31 [-Werror=format-truncation=]
  457 |                                         snprintf(usb_path, sizeof(usb_path), "%d%s%s",
      |                                                                                   ^~
  458 |                                                  (int)address, *tmp ? "." : "", tmp);
      |                                                                                 ~~~
D:/a/libserialport/libserialport/windows.c:457:41: note: 'snprintf' output between 2 and 44 bytes into a destination of size 32
  457 |                                         snprintf(usb_path, sizeof(usb_path), "%d%s%s",
      |                                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  458 |                                                  (int)address, *tmp ? "." : "", tmp);
      |                                                  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cc1.exe: all warnings being treated as errors
make[2]: *** [CMakeFiles/libserialport.dir/build.make:76: CMakeFiles/libserialport.dir/windows.c.obj] Error 1
make[1]: *** [CMakeFiles/Makefile2:83: CMakeFiles/libserialport.dir/all] Error 2
make: *** [Makefile:136: all] Error 2
```
  • Loading branch information
ndim committed Feb 26, 2024
1 parent acde2e4 commit 4e6896d
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions windows.c
Original file line number Diff line number Diff line change
Expand Up @@ -454,8 +454,9 @@ SP_PRIV enum sp_return get_port_details(struct sp_port *port)
if (CM_Get_DevNode_Registry_PropertyA(dev_inst, CM_DRP_ADDRESS,
0, &address, &size, 0) == CR_SUCCESS) {
strcpy(tmp, usb_path);
snprintf(usb_path, sizeof(usb_path), "%d%s%s",
(int)address, *tmp ? "." : "", tmp);
/* FIXME: string length, address value range, etc. */
snprintf(usb_path, sizeof(usb_path), "%u%s%s",
(BYTE)(0xff & address), *tmp ? "." : "", tmp);
}
} while (CM_Get_Parent(&dev_inst, dev_inst, 0) == CR_SUCCESS);

Expand Down

0 comments on commit 4e6896d

Please sign in to comment.