On Mon, Apr 06, 2009 at 02:00:15PM +0530, Balbir Singh wrote: > * Bharata B Rao <[email protected]> [2009-04-06 13:13:14]: > > > Fix a few compilation warnings in api.c > > > > gcc -DHAVE_CONFIG_H -I. -I.. -I../include -g -O2 -Wall -MT api.lo -MD -MP > > -MF .deps/api.Tpo -c api.c -fPIC -DPIC -o .libs/api.o > > api.c:52:1: warning: "VERSION" redefined > > In file included from ./libcgroup-internal.h:21, > > from api.c:31: > > ../config.h:129:1: warning: this is the location of the previous definition > > api.c: In function 'cgroup_parse_rules': > > api.c:353: warning: implicit declaration of function 'isblank' > > api.c: In function 'cgroup_modify_cgroup': > > api.c:1073: warning: implicit declaration of function 'asprintf' > > api.c: In function 'cg_read_stat': > > api.c:2340: warning: implicit declaration of function 'getline' > > api.c:2338: warning: 'saveptr' may be used uninitialized in this function > > > > This patch fixes the warning arising due to isblank, asprintf, getline > > and saveptr above. > > > > Signed-off-by: Bharata B Rao <[email protected]> > > --- > > src/api.c | 6 +++++- > > 1 file changed, 5 insertions(+), 1 deletion(-) > > > > --- a/src/api.c > > +++ b/src/api.c > > @@ -25,6 +25,10 @@ > > * for mistakes in APIs for reading statistics. > > */ > > > > +#ifndef _GNU_SOURCE > > +#define _GNU_SOURCE > > +#endif > > + > > #include <dirent.h> > > #include <errno.h> > > #include <libcgroup.h> > > @@ -2335,7 +2339,7 @@ int cg_read_stat(FILE *fp, struct cgroup > > char *line = NULL; > > size_t len = 0; > > ssize_t read; > > - char *token, *saveptr; > > + char *token, *saveptr = NULL; > > > > I am not convinced about this part? Why do we need to initialize > saveptr to NULL? Look at another place where we use savedptr for > strtok_r and get no warnings.
I see other uses of strtok_r using NULL-inialized saveptr argument in api.c Case 1: line 572 and 638. Case 2: line 1530 and 1560, 1567 and some not: Case 3: line 2150 and 2168, 2181 > > 1. gcc is confused But in Case 1 and Case 2, if I don't intialize the pointer, I don't get any warnings which makes me think that the below observation is true. > 2. The code has a subtle problem But I can't see what the problem is. Regards, Bharata. ------------------------------------------------------------------------------ _______________________________________________ Libcg-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/libcg-devel
