All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 1/2] uintset: NULL-check before use
@ 2019-03-01  1:01 Tim Kourt
  2019-03-01  1:01 ` [PATCH v2 2/2] unit: Sanity check for NULL l_uintset Tim Kourt
  2019-03-01  1:55 ` [PATCH v2 1/2] uintset: NULL-check before use Denis Kenzior
  0 siblings, 2 replies; 3+ messages in thread
From: Tim Kourt @ 2019-03-01  1:01 UTC (permalink / raw)
  To: ell

[-- Attachment #1: Type: text/plain, Size: 1426 bytes --]

Postpone the variable usage until after the set is NULL-checked.
---
 ell/uintset.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/ell/uintset.c b/ell/uintset.c
index 2b95ac2..1d96e68 100644
--- a/ell/uintset.c
+++ b/ell/uintset.c
@@ -202,11 +202,13 @@ LIB_EXPORT void l_uintset_free(struct l_uintset *set)
  **/
 LIB_EXPORT bool l_uintset_take(struct l_uintset *set, uint32_t number)
 {
-	uint32_t offset = (number - set->min) / BITS_PER_LONG;
+	uint32_t offset;
 
 	if (unlikely(!set))
 		return false;
 
+	offset = (number - set->min) / BITS_PER_LONG;
+
 	number -= set->min;
 
 	if (number > set->size)
@@ -233,12 +235,13 @@ LIB_EXPORT bool l_uintset_take(struct l_uintset *set, uint32_t number)
  **/
 LIB_EXPORT bool l_uintset_put(struct l_uintset *set, uint32_t number)
 {
-	uint32_t bit = number - set->min;
+	uint32_t bit;
 	uint32_t offset;
 
 	if (unlikely(!set))
 		return false;
 
+	bit = number - set->min;
 	if (bit >= set->size)
 		return false;
 
@@ -257,12 +260,13 @@ LIB_EXPORT bool l_uintset_put(struct l_uintset *set, uint32_t number)
  **/
 LIB_EXPORT bool l_uintset_contains(struct l_uintset *set, uint32_t number)
 {
-	uint32_t bit = number - set->min;
+	uint32_t bit;
 	uint32_t offset;
 
 	if (unlikely(!set))
 		return false;
 
+	bit = number - set->min;
 	if (bit >= set->size)
 		return false;
 
-- 
2.13.6


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH v2 2/2] unit: Sanity check for NULL l_uintset
  2019-03-01  1:01 [PATCH v2 1/2] uintset: NULL-check before use Tim Kourt
@ 2019-03-01  1:01 ` Tim Kourt
  2019-03-01  1:55 ` [PATCH v2 1/2] uintset: NULL-check before use Denis Kenzior
  1 sibling, 0 replies; 3+ messages in thread
From: Tim Kourt @ 2019-03-01  1:01 UTC (permalink / raw)
  To: ell

[-- Attachment #1: Type: text/plain, Size: 992 bytes --]

---
 unit/test-uintset.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/unit/test-uintset.c b/unit/test-uintset.c
index 35fc935..42d9698 100644
--- a/unit/test-uintset.c
+++ b/unit/test-uintset.c
@@ -120,6 +120,13 @@ static void test_uintset_3(const void *data)
 	l_uintset_free(set);
 }
 
+static void test_uintset_4(const void *data)
+{
+	assert(!l_uintset_take(NULL, 1));
+	assert(!l_uintset_put(NULL, 1));
+	assert(!l_uintset_contains(NULL, 1));
+}
+
 static void test_uintset_find_unused(const void *data)
 {
 	struct l_uintset *set;
@@ -167,6 +174,7 @@ int main(int argc, char *argv[])
 	l_test_add("l_uintset sanity check", test_uintset, NULL);
 	l_test_add("l_uintset sanity check #2", test_uintset_2, NULL);
 	l_test_add("l_uintset sanity check #3", test_uintset_3, NULL);
+	l_test_add("l_uintset sanity check #4", test_uintset_4, NULL);
 	l_test_add("l_uintset find unused tests", test_uintset_find_unused,
 							NULL);
 
-- 
2.13.6


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH v2 1/2] uintset: NULL-check before use
  2019-03-01  1:01 [PATCH v2 1/2] uintset: NULL-check before use Tim Kourt
  2019-03-01  1:01 ` [PATCH v2 2/2] unit: Sanity check for NULL l_uintset Tim Kourt
@ 2019-03-01  1:55 ` Denis Kenzior
  1 sibling, 0 replies; 3+ messages in thread
From: Denis Kenzior @ 2019-03-01  1:55 UTC (permalink / raw)
  To: ell

[-- Attachment #1: Type: text/plain, Size: 267 bytes --]

Hi Tim,

On 02/28/2019 07:01 PM, Tim Kourt wrote:
> Postpone the variable usage until after the set is NULL-checked.
> ---
>   ell/uintset.c | 10 +++++++---
>   1 file changed, 7 insertions(+), 3 deletions(-)
> 

Both applied, thanks.

Regards,
-Denis


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2019-03-01  1:55 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-03-01  1:01 [PATCH v2 1/2] uintset: NULL-check before use Tim Kourt
2019-03-01  1:01 ` [PATCH v2 2/2] unit: Sanity check for NULL l_uintset Tim Kourt
2019-03-01  1:55 ` [PATCH v2 1/2] uintset: NULL-check before use Denis Kenzior

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.