Monday, August 17, 2015

Digest for comp.lang.c++@googlegroups.com - 15 updates in 3 topics

Prroffessorr Fir Kenobi <profesor.fir@gmail.com>: Aug 17 02:05PM -0700

W dniu piątek, 14 sierpnia 2015 15:25:37 UTC+2 użytkownik Kate Sendall napisał:
 
> As much as I hate to admit it, programming isn't coming naturally to me - I am really finding it hard to understand and follow basic ideas. I passed my mathematics exam with flying colours - almost a 'first' - I'm not stupid. But programming is catching me out. I always have so many questions, and I can't find any answers.
 
> Thanks for taking the time to read and hopefully write back to me! :)
 
> Kate L.
 
Programming is hard, write a simple application is on average possible after
5 years of coding or so
 
Yet worse programming is harder with a levels
of advance (it both becomes harder and easier)
Im not sure if people should do programming (except the very few suicide-maniacs who want to waste their lifes)
 
yet i doubt if women should do that.. woman by its nature is more interested in real life and programming is opposite to real life
 
So i really advice do not do programming,
study biology or arts or smthng..
 
I dont quite understand what your program
has to do, could do some advice.. if this has to be something like a lego turtle you must have a way to provide commands.. How would you provide this commands... as a fragment of your program when you call some api calls 9lige forward(10); left(5); forwar(10);) of your production?
 
if so this is not so hard.. dont know SDL, though i could look at it.. it should hhave routines for drawline.. then you should only store the state of the turtle and nearly nothing more, then write some simple api that would drwaw lines based on the state, and update it to new position
 
to set up the project with your ide and sdl
seems to be the hardest part..code itself
should be easy.. (if this is the form i guess,
small api which you could use from your c code, not from text file, yet worse, whole writing interpreter for lego-like cript)
Prroffessorr Fir Kenobi <profesor.fir@gmail.com>: Aug 17 02:06PM -0700

W dniu piątek, 14 sierpnia 2015 15:25:37 UTC+2 użytkownik Kate Sendall napisał:
 
> As much as I hate to admit it, programming isn't coming naturally to me - I am really finding it hard to understand and follow basic ideas. I passed my mathematics exam with flying colours - almost a 'first' - I'm not stupid. But programming is catching me out. I always have so many questions, and I can't find any answers.
 
> Thanks for taking the time to read and hopefully write back to me! :)
 
> Kate L.
 
Programming is hard, write a simple application is on average possible after
5 years of coding or so
 
Yet worse programming is harder with a levels
of advance (it both becomes harder and easier)
Im not sure if people should do programming (except the very few suicide-maniacs who want to waste their lifes)
 
yet i doubt if women should do that.. woman by its nature is more interested in real life and programming is opposite to real life
 
So i really advice do not do programming,
study biology or arts or smthng..
 
I dont quite understand what your program
has to do, could do some advice.. if this has to be something like a lego turtle you must have a way to provide commands.. How would you provide this commands... as a fragment of your program when you call some api calls 9lige forward(10); left(5); forwar(10);) of your production?
 
if so this is not so hard.. dont know SDL, though i could look at it.. it should hhave routines for drawline.. then you should only store the state of the turtle and nearly nothing more, then write some simple api that would drwaw lines based on the state, and update it to new position
 
to set up the project with your ide and sdl
seems to be the hardest part..code itself
should be easy.. (if this is the form i guess,
small api which you could use from your c code, not from text file, yet worse, whole writing interpreter for lego-like cript)
Christopher Pisz <nospam@notanaddress.com>: Aug 17 04:18PM -0500

On 8/14/2015 8:25 AM, Kate Sendall wrote:
 
> As much as I hate to admit it, programming isn't coming naturally to me - I am really finding it hard to understand and follow basic ideas. I passed my mathematics exam with flying colours - almost a 'first' - I'm not stupid. But programming is catching me out. I always have so many questions, and I can't find any answers.
 
> Thanks for taking the time to read and hopefully write back to me! :)
 
> Kate L.
 
SDL is off topic here.
Try the www.gamedev.net forums or https://forums.libsdl.org/
 
If you have a specific question about the C++ language, maybe we can help.
 
I'd start by breaking your requirements into smaller pieces.
 
Example: "allow the user to change its parameters"
How would you like to do that? Via a UI, via an XML file, via command
line arguments?
 
Break them all down and then tackle them one at a time.
 
--
I have chosen to troll filter/ignore all subthreads containing the
words: "Rick C. Hodgins", "Flibble", and "Islam"
So, I won't be able to see or respond to any such messages
---
David Brown <david.brown@hesbynett.no>: Aug 18 01:10AM +0200

On 14/08/15 15:25, Kate Sendall wrote:
> for a year... which might not be too bad, in all honesty. It would
> give me time to learn the language and get super good at it. But
> there's a price tag to postponing. :(
 
To be brutally honest, that sounds like a better idea - you are not
going to be able to learn C++, learn SDL, and get a working program
ready in such a short time.
 
I am sceptical about any course which teaches C++ as a first language
for programming - it's a powerful but complicated language. And I'd be
sceptical about setting students tasks such as writing turtle graphics
programs using SDL without much further instructions. But of course I
don't know anything more about the course than what you've written.
 
And please ignore Fir's comments. He is not a "professor" - as far as I
can tell, he is a perpetual student with severely limited social and
communication skills (he has not posted much in this group, but is
well-known in comp.lang.c).
 
Women /should/ be involved in programming - like almost every aspect of
life, the programming world would benefit from a greater breadth of
different people. Different genders, different ages, different
languages, different countries, different educational backgrounds.
Probably the two most important skills for being a successful programmer
are a solid grounding in mathematics and logical thinking, and good,
clear communication skills. You appear to have these in place. Now all
you need is to take the time required to learn programming properly,
instead of trying to rush something half-done in time for a deadline.
 
Best of luck!
 
drawoh201@gmail.com: Aug 17 05:15AM -0700

Hi
 
I seem to not figure out whats going on with a piece of C++ code that I had written a while back, generally the program checks a logged in user's credentials to decide is he/she is authorized to access certain linux servers. The final bit in this code creates an SSH connection object. No, its not what you may think, its not using any SSH library, the code just constructs the SSH command line and executes the same using the system() call, it seems to be dumping core for some new servers my colleague has created.
 
This is the general behaviour, the user issues the command he/she is supposed to and gets the command prompt for the target server, when the user is done with their work and enters exit at the target server's command prompt, the user logs out with the following:
 
[user@machine xyz ~]$ exit
logout
Segmentation fault (core dumped)
 
 
The command that goes into the system() call looks something like this:
/usr/bin/ssh -o \"StrictHostKeyChecking no\" -i /path/to/protected/keys/id_rsa user@192.168.44.73 -p 5555 2>/dev/null
 
An this is where its dumping core, well, somewhere here:
 
 
sshconn::sshconn(creds &c){
//construct the string
char connstr[200];
char buf[250];
log lg("/path/to/log/file.log");
memset((void*)connstr,'0',200);
strcpy(connstr,"/usr/bin/ssh -o \"StrictHostKeyChecking no\" -i /path/to/protected");
strcat(connstr,c.getAuthStr());
strcat(connstr,"/keys/id_rsa ");
strcat(connstr,c.getUser());
strcat(connstr,"@");
//To continue...with getting hostname and IP
try{
getHostNameIP(c,connstr);
getPortNumber(c,connstr);
}catch(FileCantOpen &e){
e.printMsg();
exit(10);
}catch(FileCantRead &e){
e.printMsg();
exit(11);
}
strcat(connstr," 2>/dev/null");
memset(buf,'\0',sizeof(buf));
sprintf(buf,"User %s connecting with connection string %s",c.getUser(),connstr);
lg.write(buf);
system(connstr);
}
 
When I use gdb, it says that the segsegv happened at the last curly brace, but that doesn't make sense, it always happens at logout. Any clues what is causing this would be immensely helpful.
drawoh201@gmail.com: Aug 17 05:17AM -0700

> system(connstr);
> }
 
> When I use gdb, it says that the segsegv happened at the last curly brace, but that doesn't make sense, it always happens at logout. Any clues what is causing this would be immensely helpful.
 
Sorry for the typo, I mean core dumping, not "dore" dumping.
scott@slp53.sl.home (Scott Lurndal): Aug 17 01:53PM


> sshconn::sshconn(creds &c){
> //construct the string
> char connstr[200];
 
It's entirely likely that given a FQDN and long username that
you are writing beyond the end of connstr, corrupting the stack,
which would cause the SIGSEGV when returning from the function.
 
Using std::string instead of a char buffer + strcat would avoid this.
 
> char buf[250];
> log lg("/path/to/log/file.log");
> memset((void*)connstr,'0',200);
 
This should never be done. Use sizeof(connstr) instead of hardcoding 200,
or at minimum use the same #define macro for both the declaration and as
the third argument of memset.
 
I also suspect that you wanted '\0' (or just 0) instead of '0' in the memset.
Victor Bazarov <v.bazarov@comcast.invalid>: Aug 17 10:38AM -0400

On 8/17/2015 9:53 AM, Scott Lurndal wrote:
> or at minimum use the same #define macro for both the declaration and as
> the third argument of memset.
 
> I also suspect that you wanted '\0' (or just 0) instead of '0' in the memset.
 
If 0 is what the real intent was, then simple initialization should suffice:
 
char buf[200] = {};
 
V
--
I do not respond to top-posted replies, please don't ask
Barry Schwarz <schwarzb@dqel.com>: Aug 17 10:29AM -0700

On Mon, 17 Aug 2015 05:15:18 -0700 (PDT), drawoh201@gmail.com wrote:
 
<snip>
 
>The command that goes into the system() call looks something like this:
> /usr/bin/ssh -o \"StrictHostKeyChecking no\" -i /path/to/protected/keys/id_rsa user@192.168.44.73 -p 5555 2>/dev/null
 
>An this is where its dumping core, well, somewhere here:
 
<snip>
 
> strcpy(connstr,"/usr/bin/ssh -o \"StrictHostKeyChecking no\" -i /path/to/protected");
> strcat(connstr,c.getAuthStr());
> strcat(connstr,"/keys/id_rsa ");
....
 
<snip>
 
Printing the contents of connstr or at least the length of the string
it contains after each call to strcat might provide some useful
information.
 
--
Remove del for email
legalize+jeeves@mail.xmission.com (Richard): Aug 17 05:43PM

[Please do not mail me a copy of your followup]
 
slp53@pacbell.net spake the secret code
 
>Using std::string instead of a char buffer + strcat would avoid this.
 
Another perfect example of why you should stop using C-isms in C++.
--
"The Direct3D Graphics Pipeline" free book <http://tinyurl.com/d3d-pipeline>
The Computer Graphics Museum <http://computergraphicsmuseum.org>
The Terminals Wiki <http://terminals.classiccmp.org>
Legalize Adulthood! (my blog) <http://legalizeadulthood.wordpress.com>
scott@slp53.sl.home (Scott Lurndal): Aug 17 06:13PM

><yHlAx.65234$MQ3.32584@fx13.iad> thusly:
 
>>Using std::string instead of a char buffer + strcat would avoid this.
 
>Another perfect example of why you should stop using C-isms in C++.
 
And of course, counter-examples abound. snprintf could have been
used in place of strcat (and would have avoided the buffer overflow).
 
Even proper use of strncat would have sufficed.
 
The fact that bad C code is also bad in a C++ program should go without
saying.
Christopher Pisz <nospam@notanaddress.com>: Aug 17 01:17PM -0500

On 8/17/2015 1:13 PM, Scott Lurndal wrote:
 
> Even proper use of strncat would have sufficed.
 
> The fact that bad C code is also bad in a C++ program should go without
> saying.
 
Given the constant that bad programmers are everywhere, and another that
even good programmers make mistakes, it would be better for them to
first consider solutions where such mistakes can't be made, if the
outcome and efficiency is the same (or with a difference small enough to
be negligible).
 
 
 
--
I have chosen to troll filter/ignore all subthreads containing the
words: "Rick C. Hodgins", "Flibble", and "Islam"
So, I won't be able to see or respond to any such messages
---
Christian Gollwitzer <auriocus@gmx.de>: Aug 17 09:28PM +0200

> user's credentials to decide is he/she is authorized to access
> certain linux servers.
> [...] sigsegv
 
Use valgrind. Apart from the good advice from the other gentlemen, to
rewrite the code using more C++ features to help avoiding these
problems, a memory checker can probably tell you where the problem
really occurs. Run it in valgrind and fix the first error.
 
Christian
legalize+jeeves@mail.xmission.com (Richard): Aug 17 08:00PM

[Please do not mail me a copy of your followup]
 
slp53@pacbell.net spake the secret code
 
>>>Using std::string instead of a char buffer + strcat would avoid this.
 
>>Another perfect example of why you should stop using C-isms in C++.
 
>And of course, counter-examples abound. [...]
 
I'm not really sure how this is a "counter example".
 
A counter example would be an example of why you *should* use C-isms
in C++.
 
Should use them as in: gives easier to understand code when reading it
(i.e. appropriate use of abstraction) because code is read more often
than it is written and is less error-prone when using it (particularly
for error handling).
 
By all means, if you want to write C, then please head on over to
comp.lang.c, contribute to the unix kernel, or whatever. However,
please stop teaching people that writing good C++ means using C-isms.
 
My personal experience since the mid 90s is the exact opposite:
using C-isms in C++ code creates bugs, reduces maintainability,
reduces readability and prevents understanding because of its inherent
low-level nature and explosion of details. My teams have fewer
errors and less confusing code when they avoid C-isms and stick to C++.
Entire classes of bugs literally disappeared from our code once we stopped
using C style strings, for instance. The original poster's code was
another example of how simply using std::string avoids entire classes
of errors that are too easy to make with C-style strings.
 
By the way, I am not alone in this opinion nor am I alone in this
multi-decadal cumulative experience with real-world teams. This advice
is echoed by Bjarne Stroustrup in "C++ Programming Language", 4th ed. as
well as recent talks he has given on the nature of C++:
 
"The Essence of C++"
<https://www.youtube.com/watch?v=86xWVb4XIyE>
"What -- if anything -- have we learned from C++?"
<https://www.youtube.com/watch?v=2egL4y_VpYg>
"Five Popular Myths about C++"
<http://www.stroustrup.com/Myths-final.pdf>
 
The strength of C++ is that it provides the ability to create abstractions
while still yielding efficient code execution. In many cases the
abstractions are literally free when compared to the low-level detail
oriented code you would need to write in C to achieve the same end result.
--
"The Direct3D Graphics Pipeline" free book <http://tinyurl.com/d3d-pipeline>
The Computer Graphics Museum <http://computergraphicsmuseum.org>
The Terminals Wiki <http://terminals.classiccmp.org>
Legalize Adulthood! (my blog) <http://legalizeadulthood.wordpress.com>
ram@zedat.fu-berlin.de (Stefan Ram): Aug 17 01:34PM

>I seem to not figure out whats going on with a piece of C++ code
 
C code disguised as C++: fixed buffers, »strcat« with
variables, »sprintf«, now wondering about segfaults.
 
(Disclaimer: I do not know for sure whether the segfault
really is caused by an overrun of one of those buffers.
What happens when you change »200« into »2000« and »250«
into »2500«?)
 
Also, I deem your function to be decomposable into several
functions, that alone would help to locate the segfault.
You received this digest because you're subscribed to updates for this group. You can change your settings on the group membership page.
To unsubscribe from this group and stop receiving emails from it send an email to comp.lang.c+++unsubscribe@googlegroups.com.

No comments: