“libtypec” is aimed to provide a generic interface abstracting all platform complexity for user space to develop tools for efficient USB-C port management. The library can also enable development of diagnostic and debug tools to debug system issues around USB-C/USB PD topology.
if (fgets(buf, 64, fp)) {
dword = strtol(buf, NULL, 16);
} else {
/* Do some error handling */
}
The occasions that need fixing are:
/home/cking/repos/libtypec/libtypec_sysfs_ops.c: In function ‘get_opr_mode’:
/home/cking/repos/libtypec/libtypec_sysfs_ops.c:108:2: warning: ignoring return value of ‘fgets’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
108 | fgets(buf, 64, fp);
| ^~~~~~~~~~~~~~~~~~
/home/cking/repos/libtypec/libtypec_sysfs_ops.c: In function ‘get_hex_dword_from_path’:
/home/cking/repos/libtypec/libtypec_sysfs_ops.c:72:3: warning: ignoring return value of ‘fgets’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
72 | fgets(buf, 64, fp);
| ^~~~~~~~~~~~~~~~~~
/home/cking/repos/libtypec/libtypec_sysfs_ops.c: In function ‘get_dword_from_path’:
/home/cking/repos/libtypec/libtypec_sysfs_ops.c:90:3: warning: ignoring return value of ‘fgets’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
90 | fgets(buf, 64, fp);
| ^~~~~~~~~~~~~~~~~~
/home/cking/repos/libtypec/libtypec_sysfs_ops.c: In function ‘get_cable_plug_type’:
/home/cking/repos/libtypec/libtypec_sysfs_ops.c:172:2: warning: ignoring return value of ‘fgets’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
172 | fgets(buf, 64, fp);
| ^~~~~~~~~~~~~~~~~~
/home/cking/repos/libtypec/libtypec_sysfs_ops.c: In function ‘get_cable_type’:
/home/cking/repos/libtypec/libtypec_sysfs_ops.c:213:2: warning: ignoring return value of ‘fgets’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
213 | fgets(buf, 64, fp);
| ^~~~~~~~~~~~~~~~~~
/home/cking/repos/libtypec/libtypec_sysfs_ops.c: In function ‘get_cable_mode_support’:
/home/cking/repos/libtypec/libtypec_sysfs_ops.c:239:2: warning: ignoring return value of ‘fgets’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
239 | fgets(buf, 64, fp);
| ^~~~~~~~~~~~~~~~~~
/home/cking/repos/libtypec/libtypec_sysfs_ops.c: In function ‘get_pd_rev’:
/home/cking/repos/libtypec/libtypec_sysfs_ops.c:155:3: warning: ignoring return value of ‘fgets’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
155 | fgets(buf, 10, fp);
| ^~~~~~~~~~~~~~~~~~
/home/cking/repos/libtypec/libtypec_sysfs_ops.c: In function ‘get_bcd_from_rev_file’:
/home/cking/repos/libtypec/libtypec_sysfs_ops.c:137:3: warning: ignoring return value of ‘fgets’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
137 | fgets(buf, 10, fp);
There are multiple calls to fgets() where the return from the function is not being checked for failure, for example:
get_hex_dword_from_path() has:
It's a good idea to check for failure, e.g.:
The occasions that need fixing are: