From: "Ramon Vallés Puig" <vallespuigramon@gmail.com>
To: linux-sparse@vger.kernel.org
Subject: Sparse infinite loop
Date: Sat, 6 May 2023 16:58:31 +0200 [thread overview]
Message-ID: <CAMme6D7mQx5m7cbqp641ZfdOeE9UJAHJ_9xT-fAdSD8YMJfm=A@mail.gmail.com> (raw)
Hi,
I have been experiencing a situation in which the free use of global
variables has noticeably hindered my experience with Sparse.
The main issue that I wanted to report is that there is no easy way to
"clean up '' sparse in execution, leading to unexpected behaviour if
Sparse is being run multiple times in a row.
Say for instance that I am running automated tests in a given project
that uses Sparse. Each test will call sparse_initialize() in the start
up, making Sparse fill the hash_table "global" variable with the
different identifiers. But I do not have a possibility to clean up
Sparse in the teardown of the tests. While running sparse in the first
run, hash_table is an array of null pointers ( static struct ident
*hash_table[IDENT_HASH_SIZE]; ) so everything will work as expected.
However, if we run Sparse a second time, hash_table will no longer be
an empty array, instead will contain the artifacts of the first run.
This is an issue, since several functions within tokenize.c use
hash_table to check the existence of an identifier in the hash, and
assign it to the "next" ident, opening the door to a cyclic linked
list: ident = ident->next, thus falling in an infinite loop.
The issue can be reproduce just by running:
int main(int argc, char **argv)
{
struct string_list *filelist = NULL;
sparse_initialize(argc, argv, &filelist); // (1)
sparse_initialize(argc, argv, &filelist); // (2)
return 0;
}
this will never terminate as sparse_initialize (2) will most likely
fall in an infinite loop at some point inside create_hashed_ident.
A possible solution would be to add a "clean_up" function in
tokenize.c to reset the hash_table to null pointers which should be
called in between steps (1) and (2).
It would also make sense to add a security check in insert_hash, to
protect ident->next = ident.
Maybe I am missing something, but I've been stuck here for a while (bad joke).
I look forward to your reply,
best regards,
Vallés Puig, Ramon
reply other threads:[~2023-05-06 14:58 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CAMme6D7mQx5m7cbqp641ZfdOeE9UJAHJ_9xT-fAdSD8YMJfm=A@mail.gmail.com' \
--to=vallespuigramon@gmail.com \
--cc=linux-sparse@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).