How to test whether strstr() returns a null pointer or not?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Keith Thompson

    #16
    Re: How to test whether strstr() returns a null pointer or not?

    "Malcolm" <regniztar@btin ternet.com> writes:[color=blue]
    > "Keith Thompson" <kst-u@mib.org> wrote[color=green][color=darkred]
    >>> A window popped up asking for permission to report the problem to
    >>> Microsoft. That's how I knew something was wrong. Anyway, since
    >>> the program is working now, I'll just leave the mistery behind and
    >>> forget about it.[/color]
    >>
    >> It's very likely that the error was a symptom of a deeper problem
    >> that's going to bite you again later on. The change you made should
    >> not have made any difference. It's up to you whether you want to
    >> spend time tracking it down, but I'd advise doing so.
    >>[/color]
    > The bug is in the compiler. That's why MS want a bug report.[/color]

    Is it? Does the "report the problem to Microsoft" message reliably
    indicate a bug in Microsoft's compiler, or could it be triggered by a
    bug in the program itself? (I have no idea what the answer to that
    question is.)
    [color=blue]
    > The thing to do (easier said than done) is to run the code through another
    > compiler to see if everything is correct.
    > If you are stuck with a bad compiler, there's nothing much you can do,
    > except look at unusual constructs to see what is causing it to misbehave, or
    > what the OP is doing, which is to play with the code and hope the problem
    > goes away.[/color]

    If it's the result of undefined behavior in the program, recompiling
    with another compiler coud very well *seem* to correct the problem.

    --
    Keith Thompson (The_Other_Keit h) kst-u@mib.org <http://www.ghoti.net/~kst>
    San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
    We must do something. This is something. Therefore, we must do this.

    Comment

    • Malcolm

      #17
      Re: How to test whether strstr() returns a null pointer or not?

      "Keith Thompson" <kst-u@mib.org> wrote[color=blue]
      >[color=green][color=darkred]
      >>>> A window popped up asking for permission to report the problem to
      >>>> Microsoft. That's how I knew something was wrong. Anyway, since
      >>>> the program is working now, I'll just leave the mistery behind and
      >>>> forget about it.
      >>>
      >>> It's very likely that the error was a symptom of a deeper problem
      >>> that's going to bite you again later on. The change you made should
      >>> not have made any difference. It's up to you whether you want to
      >>> spend time tracking it down, but I'd advise doing so.
      >>>[/color]
      >> The bug is in the compiler. That's why MS want a bug report.[/color]
      >
      > Is it? Does the "report the problem to Microsoft" message reliably
      > indicate a bug in Microsoft's compiler, or could it be triggered by a
      > bug in the program itself? (I have no idea what the answer to that
      > question is.)
      >[/color]
      A bit OT, but yes.
      Microsoft aren't interested if a developer has introduced a bug into his
      program, except that obviously the compiler produces a diagnostic if
      possible.
      However they are interested if their own compiler / ide / debugger isn't
      working. The message indicates that their program has encountered an
      internal error, i.e. is bugged. (If it wasn't bugged before it popped up the
      message box, it is bugged after).
      That bug could be triggered by attempting to compile a legal program, or it
      could be triggered by an illegal program. Either way it is Microsoft's
      fault.[color=blue]
      >
      > If it's the result of undefined behavior in the program, recompiling
      > with another compiler coud very well *seem* to correct the problem.
      >[/color]
      What I should have asked if whether the message appears at compile time or
      run time. If it appears when the program is run under the debugger it is
      probably a bug in the debugger rather than the compiler itself. It could
      indeed be because the debugger cannot cope with undefined behaviour.
      You are right that compiling on another compiler may mask the error. Once
      your tool stop working reliably it is hard to know what to do.


      Comment

      • SM Ryan

        #18
        Re: How to test whether strstr() returns a null pointer or not?

        # if (NULL != strstr(str1, str2))
        #
        # should be equivalent to
        #
        # if (strstr(str1, str2))

        You're presuming what NULL and strstr are defined to be.

        --
        SM Ryan http://www.rawbw.com/~wyrmwif/
        Who's leading this mob?

        Comment

        • CBFalconer

          #19
          Re: How to test whether strstr() returns a null pointer or not?

          Malcolm wrote:[color=blue]
          > "Keith Thompson" <kst-u@mib.org> wrote[/color]

          talking about "if(NULL != strstr(str1,str 2))" failing.
          [color=blue][color=green]
          >>[color=darkred]
          >>> A window popped up asking for permission to report the problem to
          >>> Microsoft. That's how I knew something was wrong. Anyway, since
          >>> the program is working now, I'll just leave the mistery behind and
          >>> forget about it.[/color]
          >>
          >> It's very likely that the error was a symptom of a deeper problem
          >> that's going to bite you again later on. The change you made
          >> should not have made any difference. It's up to you whether you
          >> want to spend time tracking it down, but I'd advise doing so.
          >>[/color]
          > The bug is in the compiler. That's why MS want a bug report.
          >
          > The thing to do (easier said than done) is to run the code through
          > another compiler to see if everything is correct. If you are stuck
          > with a bad compiler, there's nothing much you can do, except look
          > at unusual constructs to see what is causing it to misbehave, or
          > what the OP is doing, which is to play with the code and hope the
          > problem goes away.[/color]

          Please don't snip attributions for material you quote.

          Assuming the author hasn't done some thing exorbitantly stupid,
          such as redefining NULL, it seems we have the usual Microsloth
          quality. If they can't correctly parse such a simple statement,
          there must be no regression suite of tests in existance.

          --
          "If you want to post a followup via groups.google.c om, don't use
          the broken "Reply" link at the bottom of the article. Click on
          "show options" at the top of the article, then click on the
          "Reply" at the bottom of the article headers." - Keith Thompson


          Comment

          • pete

            #20
            Re: How to test whether strstr() returns a null pointer or not?

            CBFalconer wrote:[color=blue]
            >
            > Malcolm wrote:[color=green]
            > > "Keith Thompson" <kst-u@mib.org> wrote[/color]
            >
            > talking about "if(NULL != strstr(str1,str 2))" failing.[/color]
            [color=blue]
            > Assuming the author hasn't done some thing exorbitantly stupid,[/color]

            Has it been established yet that <string.h> was #included?

            --
            pete

            Comment

            • Richard Bos

              #21
              Re: How to test whether strstr() returns a null pointer or not?

              "Malcolm" <regniztar@btin ternet.com> wrote:
              [color=blue]
              > "Keith Thompson" <kst-u@mib.org> wrote[color=green]
              > >[color=darkred]
              > >> A window popped up asking for permission to report the problem to
              > >> Microsoft. That's how I knew something was wrong. Anyway, since
              > >> the program is working now, I'll just leave the mistery behind and
              > >> forget about it.[/color]
              > >
              > > It's very likely that the error was a symptom of a deeper problem
              > > that's going to bite you again later on. The change you made should
              > > not have made any difference. It's up to you whether you want to
              > > spend time tracking it down, but I'd advise doing so.
              > >[/color]
              > The bug is in the compiler. That's why MS want a bug report.[/color]

              You've never used WinXP, have you?

              Richard

              Comment

              • Flash Gordon

                #22
                Re: How to test whether strstr() returns a null pointer or not?

                Keith Thompson wrote:[color=blue]
                > "Malcolm" <regniztar@btin ternet.com> writes:
                >[color=green]
                >>"Keith Thompson" <kst-u@mib.org> wrote
                >>[color=darkred]
                >>>>A window popped up asking for permission to report the problem to
                >>>>Microsoft . That's how I knew something was wrong. Anyway, since
                >>>>the program is working now, I'll just leave the mistery behind and
                >>>> forget about it.
                >>>
                >>>It's very likely that the error was a symptom of a deeper problem
                >>>that's going to bite you again later on. The change you made should
                >>>not have made any difference. It's up to you whether you want to
                >>>spend time tracking it down, but I'd advise doing so.[/color]
                >>
                >>The bug is in the compiler. That's why MS want a bug report.[/color]
                >
                > Is it? Does the "report the problem to Microsoft" message reliably
                > indicate a bug in Microsoft's compiler, or could it be triggered by a
                > bug in the program itself? (I have no idea what the answer to that
                > question is.)[/color]

                <OT>
                For the record, and from personal experience, I can state categorically
                that it can be triggered by a bug in a program. I know this because I
                have had it from code written using Delphi and found that the problem
                really was a problem in the code I had compiled.
                </OT>
                [color=blue][color=green]
                >>The thing to do (easier said than done) is to run the code through another
                >>compiler to see if everything is correct.
                >>If you are stuck with a bad compiler, there's nothing much you can do,
                >>except look at unusual constructs to see what is causing it to misbehave, or
                >>what the OP is doing, which is to play with the code and hope the problem
                >>goes away.[/color]
                >
                > If it's the result of undefined behavior in the program, recompiling
                > with another compiler coud very well *seem* to correct the problem.[/color]

                In fact, I would use this as an indication that the program almost
                certainly invokes undefined behaviour rather than thinking it means a
                compiler bug. I *have* found compiler bugs, but not anywhere near as
                often as I've found bugs in the code being compiled.
                --
                Flash Gordon
                Living in interesting times.
                Although my email address says spam, it is real and I read it.

                Comment

                • Mark

                  #23
                  Re: How to test whether strstr() returns a null pointer or not?

                  "Flash Gordon" <spam@flash-gordon.me.uk> wrote in message
                  news:46q6o2xoma .ln2@brenda.fla sh-gordon.me.uk...[color=blue]
                  > Keith Thompson wrote:[color=green]
                  >> "Malcolm" <regniztar@btin ternet.com> writes:
                  >>[color=darkred]
                  >>>"Keith Thompson" <kst-u@mib.org> wrote
                  >>>
                  >>>>>A window popped up asking for permission to report the problem to
                  >>>>>Microsof t. That's how I knew something was wrong. Anyway, since
                  >>>>>the program is working now, I'll just leave the mistery behind and
                  >>>>> forget about it.
                  >>>>
                  >>>>It's very likely that the error was a symptom of a deeper problem
                  >>>>that's going to bite you again later on. The change you made should
                  >>>>not have made any difference. It's up to you whether you want to
                  >>>>spend time tracking it down, but I'd advise doing so.
                  >>>
                  >>>The bug is in the compiler. That's why MS want a bug report.[/color]
                  >>
                  >> Is it? Does the "report the problem to Microsoft" message reliably
                  >> indicate a bug in Microsoft's compiler, or could it be triggered by a
                  >> bug in the program itself? (I have no idea what the answer to that
                  >> question is.)[/color]
                  >
                  > <OT>
                  > For the record, and from personal experience, I can state categorically
                  > that it can be triggered by a bug in a program. I know this because I have
                  > had it from code written using Delphi and found that the problem really
                  > was a problem in the code I had compiled.
                  > </OT>[/color]

                  When did this become an 'html' group?

                  #ifdef off_topic_permi tted

                  The 'report the problem to Microsoft' message may pop up whenever
                  an application crashes (dependant on how you set up windows)

                  In XP - system properties -> advanced tab -> error reporting button.

                  Has absolutely NOTHING to do with the compiler... unless it's the
                  compiler that crashed which caused the message!

                  #endif


                  Comment

                  • Keith Thompson

                    #24
                    Re: How to test whether strstr() returns a null pointer or not?

                    "Mark" <sober@localbar .com> writes:[color=blue]
                    > "Flash Gordon" <spam@flash-gordon.me.uk> wrote in message[/color]
                    [...][color=blue][color=green]
                    >> <OT>
                    >> For the record, and from personal experience, I can state categorically
                    >> that it can be triggered by a bug in a program. I know this because I have
                    >> had it from code written using Delphi and found that the problem really
                    >> was a problem in the code I had compiled.
                    >> </OT>[/color]
                    >
                    > When did this become an 'html' group?[/color]

                    It isn't; there is no "OT" tag in HTML. (Yeah, I'm taking the joke
                    too seriously.)
                    [color=blue]
                    > #ifdef off_topic_permi tted
                    >
                    > The 'report the problem to Microsoft' message may pop up whenever
                    > an application crashes (dependant on how you set up windows)
                    >
                    > In XP - system properties -> advanced tab -> error reporting button.
                    >
                    > Has absolutely NOTHING to do with the compiler... unless it's the
                    > compiler that crashed which caused the message!
                    >
                    > #endif[/color]

                    Or unless it was a bug in the compiler that caused the application to
                    crash.

                    --
                    Keith Thompson (The_Other_Keit h) kst-u@mib.org <http://www.ghoti.net/~kst>
                    San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
                    We must do something. This is something. Therefore, we must do this.

                    Comment

                    • Christopher Benson-Manica

                      #25
                      Re: How to test whether strstr() returns a null pointer or not?

                      Keith Thompson <kst-u@mib.org> wrote:
                      [color=blue]
                      > It isn't; there is no "OT" tag in HTML. (Yeah, I'm taking the joke
                      > too seriously.)[/color]

                      It is XML, however...
                      [color=blue]
                      > Or unless it was a bug in the compiler that caused the application to
                      > crash.[/color]

                      FWIW, in my experience this is not as unlikely as one might suppose.
                      We use a two-version old Borland suite, and we've learned that certain
                      operations are likely to trigger fatal compiler bugs...

                      --
                      Christopher Benson-Manica | I *should* know what I'm talking about - if I
                      ataru(at)cybers pace.org | don't, I need to know. Flames welcome.

                      Comment

                      Working...