diff mbox series

[15/15] libfrog: change project entity variable scope

Message ID 1538712196-13625-16-git-send-email-sandeen@sandeen.net (mailing list archive)
State Superseded
Headers show
Series xfsprogs: sparse fixes | expand

Commit Message

Eric Sandeen Oct. 5, 2018, 4:03 a.m. UTC
From: Eric Sandeen <sandeen@redhat.com>

The global "p" got shadowed in some other functions, and it was a bit hard
to keep track of what's what.  Change the scope of some of the project
entity retrieval function variables to make the behavior more clear.

Fixes sparse warnings about this.

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
---
 libfrog/projects.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

Comments

Christoph Hellwig Oct. 6, 2018, 10:18 a.m. UTC | #1
While the scope change is a good start the code is stull horrible.

I'd be much happier to kill these static variables entirely.  The
buffers can just be on stack, and getprent should just get a
fs_project_t to fill out passed by reference.  Same for
getprpathent.
Eric Sandeen Oct. 8, 2018, 3:50 p.m. UTC | #2
On 10/6/18 5:18 AM, Christoph Hellwig wrote:
> While the scope change is a good start the code is stull horrible.
> 
> I'd be much happier to kill these static variables entirely.  The
> buffers can just be on stack, and getprent should just get a
> fs_project_t to fill out passed by reference.  Same for
> getprpathent.
> 

I had assumed that the goal was to behave just like getpwent, which
is a void function and does not require a struct passwd to be
passed in (for example).  The symmetry of use made sense to me.

-Eric
diff mbox series

Patch

diff --git a/libfrog/projects.c b/libfrog/projects.c
index d4dda3f..91bc78f 100644
--- a/libfrog/projects.c
+++ b/libfrog/projects.c
@@ -15,12 +15,8 @@  char *projid_file;
 char *projects_file;
 
 static FILE *projects;
-static fs_project_t p;
-static char projects_buffer[512];
 
 static FILE *project_paths;
-static fs_project_path_t pp;
-static char project_paths_buffer[1024];
 
 void
 setprfiles(void)
@@ -64,8 +60,10 @@  endprpathent(void)
 fs_project_t *
 getprent(void)
 {
-	char	*idstart, *idend;
-	size_t	size = sizeof(projects_buffer) - 1;
+	static		fs_project_t p;
+	static char	projects_buffer[512];
+	char		*idstart, *idend;
+	size_t		size = sizeof(projects_buffer) - 1;
 
 	if (!projects)
 		return NULL;
@@ -125,6 +123,8 @@  getprprid(
 fs_project_path_t *
 getprpathent(void)
 {
+	static 		fs_project_path_t pp;
+	static char	project_paths_buffer[1024];
 	char		*nmstart, *nmend;
 	size_t		size = sizeof(project_paths_buffer) - 1;