null pointer question???

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • nysfp@hotmail.com

    null pointer question???

    unsigned char *Buf;
    Buf = new unsigned char[100];
    unsigned long sz = 100 * sizeof(unsigned char);
    Read(Buf,&sz);
    Occassional app crash at Read(Buf,&sz) call.
    maybe empty data, null Buf??.
    what's best way?.

    Lib:
    Read ( unsigned char * Buf ,
    unsigned long * BufSize );




    --
    Sent by nysfp from hotmail subpart from com
    This is a spam protected message. Please answer with reference header.
    Posted via http://www.usenet-replayer.com/cgi/content/new
  • Jakob Bieling

    #2
    Re: null pointer question???

    "nysfp@hotmail. com" <u557861328@spa wnkill.ip-mobilphone.net> wrote in
    message news:l.10650696 89.1681823730@[63.127.215.130]...[color=blue]
    > unsigned char *Buf;
    > Buf = new unsigned char[100];
    > unsigned long sz = 100 * sizeof(unsigned char);
    > Read(Buf,&sz);
    > Occassional app crash at Read(Buf,&sz) call.
    > maybe empty data, null Buf??.[/color]

    Maybe, yes. Maybe the error lies elsewhere. The point is that the error
    obviously occurs inside 'Read' and you have not shown anything about that
    function. If it is function of a third-party library, you should try asking
    the developers or a forum dedicated to this library. Otherwise, please show
    the relevant code of that function.

    hth
    --
    jb

    (replace y with x if you want to reply by e-mail)


    Comment

    • Kevin Goodsell

      #3
      Re: null pointer question???

      nysfp@hotmail.c om wrote:
      [color=blue]
      > unsigned char *Buf;
      > Buf = new unsigned char[100];
      > unsigned long sz = 100 * sizeof(unsigned char);[/color]

      sizeof(unsigned char) is a fancy way of writing 1.
      [color=blue]
      > Read(Buf,&sz);
      > Occassional app crash at Read(Buf,&sz) call.
      > maybe empty data, null Buf??.
      > what's best way?.
      >
      > Lib:
      > Read ( unsigned char * Buf ,
      > unsigned long * BufSize );[/color]

      Why is this a pointer? Are you sure the library is not modifying your
      size, causing it to be incorrect when you call this function later?

      -Kevin
      --
      My email address is valid, but changes periodically.
      To contact me please use the address from a recent posting.

      Comment

      • Karl Heinz Buchegger

        #4
        Re: null pointer question???



        "nysfp@hotmail. com" wrote:[color=blue]
        >
        > unsigned char *Buf;
        > Buf = new unsigned char[100];
        > unsigned long sz = 100 * sizeof(unsigned char);
        > Read(Buf,&sz);
        > Occassional app crash at Read(Buf,&sz) call.
        > maybe empty data, null Buf??.
        > what's best way?.
        >
        > Lib:
        > Read ( unsigned char * Buf ,
        > unsigned long * BufSize );
        >[/color]

        I think you are using your library the wrong way.
        An interface like the above is usually feed like this:

        unsigned char *Buf;
        unsigned long BuffSize;

        Buf = new unsigned char [ 100 ];
        BuffSize = 100;

        Read( Buf, &BuffSize );

        and read will modify BuffSize to the number of unsigned chars
        it put into Buf. But it wants to know in the beginning how large
        that buffer actually is, in order to avoid what you have seen:
        accessing the array out of bounds and thus end up in an access
        violation.

        Consult your documentation, if that's what Read does.

        --
        Karl Heinz Buchegger
        kbuchegg@gascad .at

        Comment

        • Karl Heinz Buchegger

          #5
          Re: null pointer question???



          Karl Heinz Buchegger wrote:[color=blue]
          >
          > "nysfp@hotmail. com" wrote:[color=green]
          > >
          > > unsigned char *Buf;
          > > Buf = new unsigned char[100];
          > > unsigned long sz = 100 * sizeof(unsigned char);
          > > Read(Buf,&sz);
          > > Occassional app crash at Read(Buf,&sz) call.
          > > maybe empty data, null Buf??.
          > > what's best way?.
          > >
          > > Lib:
          > > Read ( unsigned char * Buf ,
          > > unsigned long * BufSize );
          > >[/color]
          >
          > I think you are using your library the wrong way.
          > An interface like the above is usually feed like this:
          >
          > unsigned char *Buf;
          > unsigned long BuffSize;
          >
          > Buf = new unsigned char [ 100 ];
          > BuffSize = 100;
          >
          > Read( Buf, &BuffSize );
          >[/color]

          Ooops. Sorry. At reread I notices that thats exactly
          what you are doing.

          --
          Karl Heinz Buchegger
          kbuchegg@gascad .at

          Comment

          Working...