Avoiding dereference of NULL pointer

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Randy Howard

    #16
    Re: Avoiding dereference of NULL pointer

    On Sat, 15 Dec 2007 03:52:53 -0600, Tony Jackson wrote
    (in article <slrnfm78vl.jk8 .nospam@nospam. invalid>):
    Hi
    >
    I'm quite new to C programming - I have more of a Java background: maybe
    someone here can advise me.
    >
    I'm nearly finishing a little program but it has some hard-to-find bugs
    that basically lead to a couple pointers sometimes being NULL at the
    wrong time. As it stands the program just bombs out when it tries to
    dereference the NULL, which obviously isn't good (especially when it
    happens with the customer looking on!!).
    Rule #1: Don't show the customer the program before it is finished.
    I don't think there's any serious problem to worry about,

    This is almost certain to be a very poor belief to hold,
    and what I'd
    like to do is be able to ignore the dereference attempt and just carry
    on
    And this is probably not the right approach to handle it either.

    - probably the next time round the loop the pointer will be OK.

    Because of divine intervention?
    In
    Java, I'd put a try block around the main loop, and if we catch an
    exception then just jump back to the start of the main loop. What's the
    corresponding thing in C?
    Detect the error, and take appropriate action when it occurs.


    --
    Randy Howard (2reply remove FOOBAR)
    "The power of accurate observation is called cynicism by those
    who have not got it." - George Bernard Shaw





    Comment

    • Eric

      #17
      Re: Avoiding dereference of NULL pointer

      Randy Howard wrote:
      On Sat, 15 Dec 2007 03:52:53 -0600, Tony Jackson wrote
      (in article <slrnfm78vl.jk8 .nospam@nospam. invalid>):
      >
      >Hi
      >>
      >I'm quite new to C programming - I have more of a Java background: maybe
      >someone here can advise me.
      >>
      >I'm nearly finishing a little program but it has some hard-to-find bugs
      >that basically lead to a couple pointers sometimes being NULL at the
      >wrong time. As it stands the program just bombs out when it tries to
      >dereference the NULL, which obviously isn't good (especially when it
      >happens with the customer looking on!!).
      >
      Rule #1: Don't show the customer the program before it is finished.
      >
      >I don't think there's any serious problem to worry about,
      >
      >
      This is almost certain to be a very poor belief to hold,
      >
      >and what I'd
      >like to do is be able to ignore the dereference attempt and just carry
      >on
      >
      And this is probably not the right approach to handle it either.
      >
      - probably the next time round the loop the pointer will be OK.
      >
      Because of divine intervention?
      >
      >In
      >Java, I'd put a try block around the main loop, and if we catch an
      >exception then just jump back to the start of the main loop. What's the
      >correspondin g thing in C?
      >
      Detect the error, and take appropriate action when it occurs.
      >
      >
      Whats really scary is that guys like this might be writing aircraft control
      software. Got a NULL pointer? ah dont worry, just run it 4 or 5 times it
      will go. Array too small? no problemo, there's always extra space off the
      end we can use. God help us! Its no wonder that most things today that have
      any kind of built in control program are pure crap (e.g. remote controls,
      home routers, DVR's etc etc).

      Comment

      • Randy Howard

        #18
        Re: Avoiding dereference of NULL pointer

        On Fri, 28 Dec 2007 11:24:32 -0600, Eric wrote
        (in article <LOqdnWupG6nPrO janZ2dnUVZ_sOrn Z2d@comcast.com >):
        Randy Howard wrote:
        >
        >On Sat, 15 Dec 2007 03:52:53 -0600, Tony Jackson wrote
        >(in article <slrnfm78vl.jk8 .nospam@nospam. invalid>):
        >>
        >>Hi
        >>>
        >>I'm quite new to C programming - I have more of a Java background: maybe
        >>someone here can advise me.
        >>>
        >>I'm nearly finishing a little program but it has some hard-to-find bugs
        >>that basically lead to a couple pointers sometimes being NULL at the
        >>wrong time. As it stands the program just bombs out when it tries to
        >>dereference the NULL, which obviously isn't good (especially when it
        >>happens with the customer looking on!!).
        >>
        >Rule #1: Don't show the customer the program before it is finished.
        >>
        >>I don't think there's any serious problem to worry about,
        >>
        >>
        >This is almost certain to be a very poor belief to hold,
        >>
        >>and what I'd
        >>like to do is be able to ignore the dereference attempt and just carry
        >>on
        >>
        >And this is probably not the right approach to handle it either.
        >>
        >- probably the next time round the loop the pointer will be OK.
        >>
        >Because of divine intervention?
        >>
        >>In
        >>Java, I'd put a try block around the main loop, and if we catch an
        >>exception then just jump back to the start of the main loop. What's the
        >>correspondi ng thing in C?
        >>
        >Detect the error, and take appropriate action when it occurs.
        >>
        >>
        Whats really scary is that guys like this might be writing aircraft control
        software. Got a NULL pointer? ah dont worry, just run it 4 or 5 times it
        will go.

        Or a nuclear power plant, or airbag deployment code in a car, or ....
        the list is quite long these days.
        Array too small? no problemo, there's always extra space off the
        end we can use.
        Yes, and don't forget, malloc never fails. :)
        God help us! Its no wonder that most things today that have
        any kind of built in control program are pure crap (e.g. remote controls,
        home routers, DVR's etc etc).
        Yes, when everything is built by the lowest bidder, and nobody will buy
        anything that's not on the top of the list, when sorted by price low to
        high, then you get mostly crap.


        --
        Randy Howard (2reply remove FOOBAR)
        "The power of accurate observation is called cynicism by those
        who have not got it." - George Bernard Shaw





        Comment

        Working...