[LTP] [PATCH V2 6/9] testcases/lib: Add tst_random decmical integer generator

Chunyu Hu chuhu@redhat.com
Thu May 5 01:40:11 CEST 2016



----- Original Message -----
> From: "Chunyu Hu" <chuhu@redhat.com>
> To: "Cyril Hrubis" <chrubis@suse.cz>
> Cc: liwan@redhat.com, ltp@lists.linux.it
> Sent: Thursday, May 5, 2016 12:28:30 AM
> Subject: Re: [LTP] [PATCH V2 6/9] testcases/lib: Add tst_random decmical integer generator
> 
> 
> 
> ----- Original Message -----
> > From: "Cyril Hrubis" <chrubis@suse.cz>
> > To: "Chunyu Hu" <chuhu@redhat.com>
> > Cc: ltp@lists.linux.it, liwan@redhat.com
> > Sent: Wednesday, May 4, 2016 11:55:31 PM
> > Subject: Re: [LTP] [PATCH V2 6/9] testcases/lib: Add tst_random decmical
> > integer generator
> > 
> > Hi!
> > > Looks like we just need to compare with ( *end != '\0' ), as argv[1] or
> > > argv[2] can't be '\0' (NULL) as it has been filtered by (argc <2 || argc
> > > >
> > > 3).

I proved to be wrong, which pointed bye you  below. BTW, i also
changed the argc check way to 

 if (argc != 2 && argc != 3)

I think this clearer than 
 if (argc < 2 || argc > 3 )



> > > And i just verified this with this debug line:
> > > 
> > >    printf("end = %p, *end = %c\n", end, *end);
> > 
> > What will happen when you call:
> > 
> > tst_random "" ""
> > 
> > Or more realistic case when FOO is not defined and you do:
> > 
> > tst_random "$FOO"
> > 
> > Note that empty string in C is an array with first element set to 0.
> 
> I was so hurried to send out the patch :/. You are right. I missed your
> mentioned here.  I added some debug line, proving you are right.
> 
> 
>         printf("argv[1] = [%d]\n", argv[1][0]);
>         printf("argv[3] = [%d]\n", argv[3]);
>         printf("end = %p, *end = [%d]\n", end, *end);
> 
> ./a.out "" ""
> 
> argv[1] = [0]
> argv[3] = [0]
> end = 0x7ffc3d49861f, *end = [0]
> 
> I will reorganize this check later, my brain is so slow now. Thank you.

after some rest, i considered it as your suggestion and man page. I think
below condition is enough, if you don't have objection for this, i will 
use this in next step. Thanks.

if (!(argv[1][0] != '\0' && *end == '\0'))


> 
> > --
> > Cyril Hrubis
> > chrubis@suse.cz
> > 
> 
> --
> Regards,
> Chunyu Hu
> 
> --
> Mailing list info: https://lists.linux.it/listinfo/ltp
> 

-- 
Regards,
Chunyu Hu



More information about the ltp mailing list