safe sprintf snprintf(3) considered harmful
1
Name:
Anonymous
2008-09-30 14:21
You should use int _snprintf_s(char *buffer, size_t sizeOfBuffer, size_t count, const char *format,... ); instead.
2
Name:
Anonymous
2008-09-30 14:50
fuck off
3
Name:
Anonymous
2008-09-30 16:18
Use an implementation function instead of the standard one?
no. see
>>2
4
Name:
Anonymous
2008-09-30 16:57
fuck off
5
Name:
Anonymous
2008-09-30 17:11
I am OP
Yes, the idea is disgusting, but it's not only microsoft now, other people are adopting it as well. I thought we could have a nice discussion about how this is right or wrong.
6
Name:
Anonymous
2008-09-30 18:25
>>5
Use string objects with length counts instead of null-terminated character sequences, thread over.
7
Name:
Anonix developper
2008-09-30 18:53
>>6
STD AND C++ IS BLOAT DIG PIGDUSTING
8
Name:
Anonymous
2008-09-30 19:17
>>7
Who said anything about C++?
9
Name:
Anonymous
2008-09-30 19:37
10
Name:
Anonymous
2008-09-30 19:40
11
Name:
Anonymous
2008-09-30 20:00
>>7
STD is ridiculously streamlined and optimizes into almost nothing. Enjoy your FAIL worldview.
12
Name:
Anonymous
2008-09-30 20:23
>>11
Too bad it bloats the executable by four megabytes and degrades the performace by an order of two magnitudes.
13
Name:
Anonymous
2008-09-30 20:32
>>12
If and only if you include the entire CRT in the executable as a static library.
14
Name:
Anonymous
2008-09-30 20:32
>>11
ls -l /usr/lib/libstdc++.*
15
Name:
Anonymous
2008-09-30 20:56
>>13
That's what I'd do if I was using my own library as well, except that it wouldn't have every component depend on every other.
Oh, and it'd be written in blazing fast C.
16
Name:
Anonymous
2008-09-30 21:00
>>12,13
Welcome back to 1993. Don't worry, we'll eventually get better machines in ten years time.
17
Name:
Anonymous
2008-09-30 21:00
>>14
SOU NAN DESS KARR?
-r--r--r-- 1 root wheel 1522998 Mar 12 2008 /usr/lib/libstdc++.a
-r--r--r-- 1 root wheel 956095 Nov 23 2007 /usr/lib/libstdc++.so.42.0
-r--r--r-- 1 root wheel 955948 Mar 12 2008 /usr/lib/libstdc++.so.44.0
18
Name:
Anonymous
2008-10-01 2:26
>>15
C++ is faster than C, you fucking neo-luddite. Get your head out of your Amish ass.
19
Name:
Anonymous
2008-10-01 2:35
fuck all this talk of "safe" code, just check your input size if it's fixed, or use dynamically expanding buffers if it's not.
and if you can't prove an upper bound on the length of the data you're generating and supplying to sprintf, then you shouldn't be programming.
it's as simple as that.
20
Name:
Anonymous
2008-10-01 2:47
21
Name:
Anonymous
2008-10-01 4:31
>>20
0/10
C++ actually is faster.
22
Name:
Anonymous
2008-10-01 4:43
>>21
Faster at trivial programs from shootout.alioth.debian.org that are not using most of c++ functionality except templates which are unsuited for large programs because of infinitely long compile times?
23
Name:
Anonymous
2008-10-01 4:51
>>19
5/10
Obvious troll, exudes arrogance out of every orifice.
24
Name:
Anonymous
2008-10-01 6:07
>>22
Fuck the shootout shit. C++ is faster at function calls (due to having specific registers reserved for
this instead of always lugging around explicit parameters), faster at anything dispatched than cobbled together C shit, and the template expansions from the STL libs have all sorts of really tight optimizations that you're not going to have in your "yet another shitty variable-size array" implementation.
25
Name:
Anonymous
2008-10-01 6:41
>>24
9/10, almost got trolled.
How can C++ be faster at features C doesn't even have?
26
Name:
Anonymous
2008-10-01 10:09
RAGE
27
Name:
Anonymous
2008-10-01 11:24
Ok, that's it. The rating troll has gone too far. Stop fucking rating posts that aren't trolling.
28
Name:
Anonymous
2008-10-01 11:34
>>24
What compiler does these ``really tight optimizations''?
29
Name:
Anonymous
2008-10-01 11:49
30
Name:
Anonymous
2008-10-01 12:46
use -h with -l to avoid being off by an order of magnitude mistakes.
31
Name:
Anonymous
2008-10-01 13:06
32
Name:
Anonymous
2008-10-01 13:08
>>29
I googled for ``STL c++'', and found this program in the very first result:
#include <iostream>
#include <vector>
#include <string>
using namespace std;
main()
{
vector<string> SS;
SS.push_back("The number is 10");
SS.push_back("The number is 20");
SS.push_back("The number is 30");
cout << "Loop by index:" << endl;
int ii;
for(ii=0; ii < SS.size(); ii++)
{
cout << SS[ii] << endl;
}
cout << endl << "Constant Iterator:" << endl;
vector<string>::const_iterator cii;
for(cii=SS.begin(); cii!=SS.end(); cii++)
{
cout << *cii << endl;
}
cout << endl << "Reverse Iterator:" << endl;
vector<string>::reverse_iterator rii;
for(rii=SS.rbegin(); rii!=SS.rend(); ++rii)
{
cout << *rii << endl;
}
cout << endl << "Sample Output:" << endl;
cout << SS.size() << endl;
cout << SS[2] << endl;
swap(SS[0], SS[2]);
cout << SS[2] << endl;
}
It outputs:
Loop by index:
The number is 10
The number is 20
The number is 30
Constant Iterator:
The number is 10
The number is 20
The number is 30
Reverse Iterator:
The number is 30
The number is 20
The number is 10
Sample Output:
3
The number is 30
The number is 10
I compiled it with
g++ go.cpp -O3 -S -o go.S and uploaded result to pastebin:
http://pastebin.com/m335e2398
Do you call this monstrosity
really tight optimization ?
33
Name:
Anonymous
2008-10-01 13:36
>>32
You, sir, have been exponentially trolled.
34
Name:
Anonymous
2008-10-01 14:02
>>33
Acting stupid does not equal trolling
35
Name:
Anonymous
2008-10-01 14:43
>>32
You forgot to funroll your loops.
36
Name:
Anonymous
2008-10-01 15:04
>>33
nlog(n) trolling is far from exponential.
37
Name:
Anonymous
2008-10-01 15:10
>>35
That's not the point
38
Name:
Anonymous
2008-10-01 18:25
>>25
How can C++ be faster at features C doesn't even have?
Because you're writing actual programs. If the language doesn't support it, you generally end up making your own shitty version of stuff that other languages support much better.
in b4 Greenspun's 10th rule
39
Name:
Anonymous
2008-10-01 23:22
40
Name:
Anonymous
2008-10-02 0:20
Unrelated: In
>>32 main has omitted return type, which defaults to int in C. Isn't it not allowed in Sepples?
41
Name:
Anonymous
2008-10-02 0:27
>>40
Correct,
>>32 is malformed.
42
Name:
Anonymous
2008-10-02 6:14
>>41
Ah, yeah. g++ starts complaining about it with -Wall.
43
Name:
Anonymous
2008-10-02 13:54
Why does g++ not default to -Wall?
44
Name:
Anonymous
2008-10-02 16:14
45
Name:
Anonymous
2008-10-02 16:19
>>43
Because
EXPERT is the default programmer and he does not need nitpicky warnings.
46
Name:
Anonymous
2009-09-17 15:19
Lain.
47
Name:
Anonymous
2011-02-03 8:17