Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #24691

Re: ridiculous warning or not?

From Ike Naar <ike@iceland.freeshell.org>
Newsgroups comp.lang.c
Subject Re: ridiculous warning or not?
Date 2012-08-21 22:09 +0000
Organization A noiseless patient Spider
Message-ID <slrn3vfsk381ov.1kt.ike@iceland.freeshell.org> (permalink)
References <f87cd21e-eec8-4085-93c9-9315da17e455@googlegroups.com> <22eb92c9-bac8-40dd-809e-4534b468c54c@googlegroups.com> <821c860e-7c74-4a6e-961a-96c70c317a47@googlegroups.com> <0.76516eb12abe6e8db3a7.20120821210724BST.87obm43t6r.fsf@bsb.me.uk> <9aa2c206-bbe1-43aa-b787-5e11db1269a6@googlegroups.com>

Show all headers | View raw


On 2012-08-21, 88888 Dihedral <dihedral88888@googlemail.com> wrote:
> On Wednesday, August 22, 2012 4:07:24 AM UTC+8, Ben Bacarisse wrote:
>> 88888 Dihedral <dihedral88888@googlemail.com> writes:
>> 
>> <snip>
>> > int **x ; // a pointer to a pointer of an integer
>> > int* x2[4000]; // an array of 4000 pointers to integers in the heap?
>> > int i,j; //i-n for ineger idexing
>> >
>> > // malloc might fail
>> >
>> > for(j=0;j<4000;j++)
>> >   if ((  x2[j]=malloc(4000* sizeof(int *))) ==NULL)
>> 
>> Wrong type in the malloc call.  Using the often quoted idiom here would
>> have prevented this problem:
>> 
>>    x2[j] = malloc(4000 * sizeof *x2[j])
>> 
>> >     {i=-1; break; }
>> >
>> > if (i==-1) 
>> > { //error trapping here ....}
>> 
>> i may be -1 even without any error.
>
> You are right check j for the value  that equals 4001 or not  is the
> more elegant way.

Not 4001, but 4000.

Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

ridiculous warning or not? kerravon <kerravon@w3.to> - 2012-08-20 02:41 -0700
  Re: ridiculous warning or not? Eric Sosman <esosman@ieee-dot-org.invalid> - 2012-08-20 07:55 -0400
  Re: ridiculous warning or not? army1987 <army1987@ask-for-it.invalid> - 2012-08-20 19:11 +0000
  Re: ridiculous warning or not? Kenneth Brody <kenbrody@spamcop.net> - 2012-08-20 16:09 -0400
    Re: ridiculous warning or not? Tim Rentsch <txr@alumni.caltech.edu> - 2012-09-07 07:29 -0700
  Re: ridiculous warning or not? Andrew Cooper <amc96@cam.ac.uk> - 2012-08-21 00:36 +0100
  Re: ridiculous warning or not? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-08-21 01:41 +0100
    Re: ridiculous warning or not? Keith Thompson <kst-u@mib.org> - 2012-08-20 18:59 -0700
      Re: ridiculous warning or not? Tim Rentsch <txr@alumni.caltech.edu> - 2012-09-07 08:03 -0700
        Re: ridiculous warning or not? Keith Thompson <kst-u@mib.org> - 2012-09-07 14:37 -0700
          Re: ridiculous warning or not? Tim Rentsch <txr@alumni.caltech.edu> - 2012-09-07 19:17 -0700
            Re: ridiculous warning or not? Keith Thompson <kst-u@mib.org> - 2012-09-07 19:56 -0700
              Re: ridiculous warning or not? Tim Rentsch <txr@alumni.caltech.edu> - 2012-09-08 06:30 -0700
    Re: ridiculous warning or not? Tim Rentsch <txr@alumni.caltech.edu> - 2012-09-07 07:57 -0700
      Re: ridiculous warning or not? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-09-08 00:25 +0100
        Re: ridiculous warning or not? Tim Rentsch <txr@alumni.caltech.edu> - 2012-09-07 18:58 -0700
          Re: ridiculous warning or not? Keith Thompson <kst-u@mib.org> - 2012-09-07 19:26 -0700
            Re: ridiculous warning or not? Tim Rentsch <txr@alumni.caltech.edu> - 2012-09-08 06:26 -0700
              Re: ridiculous warning or not? Keith Thompson <kst-u@mib.org> - 2012-09-08 11:33 -0700
                Re: ridiculous warning or not? Tim Rentsch <txr@alumni.caltech.edu> - 2012-12-17 14:39 -0800
                Re: ridiculous warning or not? Keith Thompson <kst-u@mib.org> - 2012-12-17 15:56 -0800
                Re: ridiculous warning or not? Tim Rentsch <txr@alumni.caltech.edu> - 2012-12-20 10:31 -0800
                Re: ridiculous warning or not? Keith Thompson <kst-u@mib.org> - 2012-12-20 16:57 -0800
                Re: ridiculous warning or not? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-12-21 03:11 +0000
                Re: ridiculous warning or not? Tim Rentsch <txr@alumni.caltech.edu> - 2012-12-21 09:06 -0800
          Re: ridiculous warning or not? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-09-08 03:42 +0100
            Re: ridiculous warning or not? Tim Rentsch <txr@alumni.caltech.edu> - 2012-09-08 06:01 -0700
              Re: ridiculous warning or not? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-09-08 14:45 +0100
                Re: ridiculous warning or not? Keith Thompson <kst-u@mib.org> - 2012-09-08 11:28 -0700
                Re: ridiculous warning or not? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-09-08 22:53 +0100
  Re: ridiculous warning or not? kerravon <kerravon@w3.to> - 2012-08-21 03:25 -0700
    Re: ridiculous warning or not? 88888 Dihedral <dihedral88888@googlemail.com> - 2012-08-21 11:20 -0700
      Re: ridiculous warning or not? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-08-21 21:07 +0100
        Re: ridiculous warning or not? 88888 Dihedral <dihedral88888@googlemail.com> - 2012-08-21 14:39 -0700
          Re: ridiculous warning or not? Ike Naar <ike@iceland.freeshell.org> - 2012-08-21 22:09 +0000
            Re: ridiculous warning or not? 88888 Dihedral <dihedral88888@googlemail.com> - 2012-08-21 15:13 -0700
              Re: ridiculous warning or not? Fred K <fred.l.kleinschmidt@gmail.com> - 2012-08-22 07:17 -0700

csiph-web