NetBSD-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

lib/60249: bitstring macro type errors



>Number:         60249
>Category:       lib
>Synopsis:       bitstring bit_ffc(), bit_ffs() type conflicts
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    lib-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Mon May 11 20:35:00 +0000 2026
>Originator:     bch
>Release:        NetBSD 11.99.5
>Organization:
	method logic
>Environment:
System: NetBSD katy 11.99.5 NetBSD 11.99.5 (GENERIC) #480: Wed Apr 22 09:41:53 PDT 2026 root@katy:/usr/obj/sys/arch/amd64/compile/GENERIC amd64
Architecture: x86_64
Machine: amd64
>Description:
        in file /usr/include/bitstring.h

	calling macro bit_ffc() as described (bitstring(3), definition) throws throws conversion errors in gcc (not clang though(?)) because of type mismatches.

        bit_ffc(const bitstr_t *name, size_t nbits, int *value);

error: conversion from 'size_t' {aka 'long unsigned int'} to 'int' may change value [-Werror=conversion]
  620 |   bit_ffc(id_bitmap, 64, &client_info->slot);
      |   ^~~~~~~

  bit_ffs() shares same signature. Curious to know if *size_t -sized
  bitmaps are even a thing anybody uses or can imagine using... or
  whether int alone is large enough. Should this use int (or ssize_t)
  and just test for nbits>=0?


  Aside: as implemented, one also needs calloc(), declared in
  <stdlib.h> -- does this need to be added to <bitstring.h>?

>How-To-Repeat:

Compile w/ -Wconversion

$ cc -o ffc -Wconversion ./ffc.c

== ffc.c =
==========
#include <sys/types.h>
#include <bitstring.h>
#include <stdlib.h> /** should bitstring.h bring this along? */

int
main(int argc, char *argv[])
{
  bitstr_t       *bitmap;
  int val;

  bitmap = bit_alloc(64);
  bit_ffc(bitmap, 64, &val);

  return 0;
}

>Fix:
	See desc.




Home | Main Index | Thread Index | Old Index