All of lore.kernel.org
 help / color / mirror / Atom feed
* [cocci] how to check a for "don't care" state of a variable?
@ 2022-10-08  3:09 ` Kees Cook
  0 siblings, 0 replies; 16+ messages in thread
From: Kees Cook @ 2022-10-07 23:11 UTC (permalink / raw)
  To: cocci

Hi!

I was looking at doing some conversions for this[1], and I wasn't sure
how to check for removing a variable assignment if there was either no
more uses or the next use was an assignment itself.

i.e.:

	var = 1;
	other = func(var);

turns into:

	other = func(1);

but this would not:

	var = 1;
	other = func(var);
	report(var);

without getting confused by:

	var = 1;
	other = func(var);
	var = 5;



@multi_line@
identifier randfunc =~ "get_random_int|prandom_u32|get_random_u32";
identifier RAND;
expression E;
type TYPE;
@@

(
-       RAND = randfunc();
        ... when != RAND
-       RAND %= (E);
+       RAND = prandom_u32_max(E);
|
-       RAND = randfunc();
        ... when != RAND
-       ((TYPE)RAND % (E))
+       prandom_u32_max(E)
// This is wrong: we need to check that RAND is either assigned or never
// accessed again
)


I thought I could do this:

	... when != RAND
	<... RAND = EXP; ...>

But this appears to be invalid syntax...

-Kees

[1] https://lore.kernel.org/lkml/202210071241.445289C5@keescook/

-- 
Kees Cook

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

end of thread, other threads:[~2022-10-10 19:12 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-10-07 23:11 [cocci] how to check a for "don't care" state of a variable? Kees Cook
2022-10-08  3:09 ` Kees Cook
2022-10-08  7:43 ` Julia Lawall
2022-10-08  8:55   ` Markus Elfring
2022-10-08  9:00     ` Julia Lawall
2022-10-08  9:15       ` Markus Elfring
2022-10-08 11:02   ` Markus Elfring
2022-10-09 15:10   ` Kees Cook
2022-10-09 15:12     ` Julia Lawall
2022-10-09 15:56     ` Markus Elfring
2022-10-09 17:37     ` Kees Cook
2022-10-09 18:02       ` Julia Lawall
2022-10-09 18:16         ` Kees Cook
2022-10-09 18:19           ` Julia Lawall
2022-10-10  2:16             ` Jason A. Donenfeld
2022-10-10 19:12       ` [cocci] Reconsidering selected SmPL code Markus Elfring

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.