diff options
| author | Garrett D'Amore <garrett@damore.org> | 2018-07-06 12:53:06 -0700 |
|---|---|---|
| committer | Garrett D'Amore <garrett@damore.org> | 2018-07-06 17:45:45 -0700 |
| commit | 89cba92d13fbc5e059336fd054be30e50d8a2621 (patch) | |
| tree | 4752d4ba6d2f5ae3647b7f4560db77b00e62c6f0 /src/core/idhash.c | |
| parent | 71b749dc3f948504f561098b1533154c2db7ec5e (diff) | |
| download | nng-89cba92d13fbc5e059336fd054be30e50d8a2621.tar.gz nng-89cba92d13fbc5e059336fd054be30e50d8a2621.tar.bz2 nng-89cba92d13fbc5e059336fd054be30e50d8a2621.zip | |
fixes #581 nni_idhash could use 32-bit variant
Diffstat (limited to 'src/core/idhash.c')
| -rw-r--r-- | src/core/idhash.c | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/src/core/idhash.c b/src/core/idhash.c index 0de83eb1..0ba9056c 100644 --- a/src/core/idhash.c +++ b/src/core/idhash.c @@ -306,3 +306,20 @@ nni_idhash_alloc(nni_idhash *h, uint64_t *idp, void *val) return (rv); } + +int +nni_idhash_alloc32(nni_idhash *h, uint32_t *idp, void *val) +{ + uint64_t id64; + int rv; + + if ((rv = nni_idhash_alloc(h, &id64, val)) == 0) { + if (id64 > 0xffffffffull) { + nni_idhash_remove(h, id64); + rv = NNG_EINVAL; + } else { + *idp = (uint32_t) id64; + } + } + return (rv); +} |
