Thread: strcpy get errors

  1. #106
    Stoned Witch Barney McGrew's Avatar
    Join Date
    Oct 2012
    Location
    astaylea
    Posts
    420
    I never once claimed that gets is safe. I said it can be used safely. Do you see the difference?

  2. #107
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    Yes, I do. If you were responsible for ensuring the space shuttle was safe, you would ensure the nose wheel was fully inflated but forget to ensure the astronauts had breathable air.
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

  3. #108
    Stoned Witch Barney McGrew's Avatar
    Join Date
    Oct 2012
    Location
    astaylea
    Posts
    420
    I don't think you do since you seem to think I've suggested that gets is inherently safe, when that's basically the kind of perspective I'm arguing against.

    Fact is, it works in a predictable way except for two factors (the parameter it receives and the state of stdin). You can't evaluate the safety of gets by ignoring those two factors, you need to take them into account when speaking of safety. By treating it as an individual unit you pretend that those two factors don't matter and that it's automatically 'safe' or 'unsafe', which is obviously stupid. If you can guarantee that the data it reads from stdin will fit into the memory pointed to by its first parameter, then *the call* is safe, otherwise it's liable to break, hence making *the call* unsafe.

  4. #109
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,613
    If you can guarantee that the data it reads from stdin will fit into the memory pointed to by its first parameter, then *the call* is safe, otherwise it's liable to break, hence making *the call* unsafe.
    Then how about an open challenge? Please, for the audience, programatically determine that gets() is safe. I'm genuinely curious, but I bet whatever you do is more trouble than it's worth.

  5. #110
    Stoned Witch Barney McGrew's Avatar
    Join Date
    Oct 2012
    Location
    astaylea
    Posts
    420

  6. #111
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,613
    Quote Originally Posted by Barney McGrew View Post
    I can't accept that.

    Code:
    mingw32-gcc.exe -Wall  -g  -pedantic -Wextra -Wall -ansi -g    -c C:\Users\Josh2\Documents\foo\foo.c -o obj\Debug\foo.o
    C:\Users\Josh2\Documents\foo\foo.c: In function 'main':
    C:\Users\Josh2\Documents\foo\foo.c:2: warning: control reaches end of non-void function
    mingw32-g++.exe  -o bin\Debug\foo.exe obj\Debug\foo.o    
    Output size is 25.42 KB
    Process terminated with status 0 (0 minutes, 0 seconds)
    0 errors, 1 warnings
    Even so, the program has the following results.

    Process returned 2686751 (0x28FF1F) execution time : 0.016 s
    Press any key to continue.


    What on earth are you trying to prove?

  7. #112
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    That one would be a bad example, though for the claim made, I think it has no flaws (if I understand what is allowed for ungetc correctly). A better example, but it has flaws that Barney McGrew glossed over.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  8. #113
    Stoned Witch Barney McGrew's Avatar
    Join Date
    Oct 2012
    Location
    astaylea
    Posts
    420
    mingw32-g++.exe

    C:\Users\Josh2\Documents\foo\foo.c:2: warning: control reaches end of non-void function

    Process returned 2686751 (0x28FF1F) execution time : 0.016 s
    Your C implementation is clearly broken. Apparently it's a C++ implementation.

    What on earth are you trying to prove?
    Nothing really, I just made a comment and people started responding to it, so I started responding to them. What fun it's been.

    edit: But if you want to get a better idea of the topic, my initial post is here: strcpy get errors
    Last edited by Barney McGrew; 01-18-2013 at 02:51 AM.

  9. #114
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,613
    Your C implementation is clearly broken. Apparently it's a C++ implementation.
    MinGW uses g++ to link C programs, which is not broken. If you read the whole log, it also uses gcc to generate the object code.

    Nothing really, I just made a comment and people started responding to it, so I started responding to them. What fun it's been.
    Well you are being a bit of a troll. The problem with gets() is well understood. And the only thing you can do is write code with it that no one has any business using.

  10. #115
    Stoned Witch Barney McGrew's Avatar
    Join Date
    Oct 2012
    Location
    astaylea
    Posts
    420
    MinGW uses g++ to link C programs, which is not broken. If you read the whole log, it also uses gcc to generate the object code.
    Try building it with -std=c99 or -std=c11 then. Or simply type “return 0;” at the end of main's definition.

    The problem with gets() is well understood.
    Perhaps. But the invalidity of the common claim “gets is impossible to use safely” isn't.
    Last edited by Barney McGrew; 01-18-2013 at 03:02 AM. Reason: fixed cflags

  11. #116
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,613
    Try building it with -std=c99 or -std=c11 then. Or simply type “return 0;” at the end of main's definition.
    :S

    I had the lowly expectation of being able to use gets() to retrieve input. I am not interested in fancy ways of writing skeleton programs. But hey you know, it's good I guess that you're such a stickler for being correct. Try seeing the forest for the trees.

  12. #117
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by Barney McGrew
    But the invalidity of the common claim “gets is impossible to use safely” isn't.
    I think that the claim that gets is impossible to use safely is indeed invalid. As I stated in post #49, it is possible to use gets safely, but the responsibility for safe use lies with the user, hence gets cannot be rendered safe by the program, from what I understood at the time.

    However, you approached this from a different angle where you stated that the program itself can ensure the safe use. In this, sorry, as I noted earlier, I am still not convinced, because the first of your two counter examples is valid but does not demonstrate a reasonable use of gets, whereas the other is invalid because, besides use of a function that apparently results in undefined behaviour, there are reasonable scenarios in which it fails with no recourse (other than not using gets) that you have provided.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  13. #118
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    Quote Originally Posted by Barney McGrew View Post
    I don't think you do since you seem to think I've suggested that gets is inherently safe.
    I never suggested you thought that.

    I have suggested that you are using an obscure example that doesn't work to support your claim that gets() can be used safely (if ... and if .... and if ......).
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

  14. #119
    Stoned Witch Barney McGrew's Avatar
    Join Date
    Oct 2012
    Location
    astaylea
    Posts
    420
    I had the lowly expectation of being able to use gets() to retrieve input.
    Pfft. That sounds like kid stuff. I use it to write crappy programs that use fseek and stuff.

    I am not interested in fancy ways of writing skeleton programs.
    There aren't any skeletons in my programs.

    But hey you know, it's good I guess that you're such a stickler for being correct.
    Why?

    Try seeing the forest for the trees.
    There aren't any forests near where I live, unfortunately.

    As I stated in post #49, it is possible to use gets safely, but the responsibility for safe use lies with the user, hence gets cannot be rendered safe by the program, from what I understood at the time.
    I consider that unsafe because it can potentially break, as the input received during interpretation, through stdin, ought to be considered uncontrollable and unpredictable.

    In this, sorry, as I noted earlier, I am still not convinced, because the first of your two counter examples is valid but does not demonstrate a reasonable use of gets
    I suppose you have a different interpretation of the word 'use' then. For me it's 'wherever gets is called', perhaps 'use' might imply 'used for a useful purpose' for you. I dunno.

    I never suggested you thought that.
    See
    You have just contradicted your own insistence that a use case which is rarely (*cough* virtually never) used in practice, is significant in claiming that gets() is safe.
    Last edited by Barney McGrew; 01-18-2013 at 03:37 AM. Reason: fixed a quote

  15. #120
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by Barney McGrew
    I consider that unsafe because it can potentially break, as the input received during interpretation, through stdin, ought to be considered uncontrollable and unpredictable.
    Yes, it ought to be treated as such. However, in some special cases, it is really is okay... for now.

    Quote Originally Posted by Barney McGrew
    I suppose you have a different interpretation of the word 'use' then. For me it's 'wherever gets is called', perhaps 'use' might imply 'used for a useful purpose' for you. I dunno.
    Yes. It should be useful. Otherwise, what's the point? It doesn't help me explain anything practical to a beginner wondering why gets should not be used.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help using strcpy
    By laxkrzy in forum C Programming
    Replies: 1
    Last Post: 11-15-2010, 11:09 PM
  2. Replies: 1
    Last Post: 06-19-2010, 07:42 AM
  3. What's up with this strcpy?
    By fanoliv in forum C Programming
    Replies: 7
    Last Post: 06-19-2006, 05:24 PM
  4. strcpy
    By Tibo in forum C Programming
    Replies: 2
    Last Post: 03-27-2003, 07:02 AM
  5. strcpy
    By Unregistered in forum C++ Programming
    Replies: 6
    Last Post: 08-01-2002, 01:39 PM