]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libblkid: make example more robust
authorKarel Zak <kzak@redhat.com>
Wed, 15 May 2024 11:24:29 +0000 (13:24 +0200)
committerKarel Zak <kzak@redhat.com>
Wed, 15 May 2024 11:24:29 +0000 (13:24 +0200)
Fixes: https://github.com/util-linux/util-linux/issues/3043
Signed-off-by: Karel Zak <kzak@redhat.com>
libblkid/src/partitions/partitions.c

index e096cf8f72aff3c611473b14603e4ea3e872399b..07a5d1ad6f08be5823fc0ea5d7bdebdad08ad15a 100644 (file)
  *  <programlisting>
  * blkid_probe pr;
  * blkid_partlist ls;
- * int nparts, i;
+ * int nparts = 0, i;
  *
  * pr = blkid_new_probe_from_filename(devname);
  * if (!pr)
  *     err("%s: failed to open device", devname);
- *
  * ls = blkid_probe_get_partitions(pr);
- * nparts = blkid_partlist_numof_partitions(ls);
+ * if (ls)
+ *     nparts = blkid_partlist_numof_partitions(ls);
  *
  * for (i = 0; i < nparts; i++) {
  *      blkid_partition par = blkid_partlist_get_partition(ls, i);