|
Aleksei Vasiliev posted:https://code.google.com/p/java-image-scaling/source/browse/trunk/src/main/java/com/mortennobel/imagescaling/ResampleOp.java#140 Dude makes a final copy of that variable so it can be refered to in the closure that's supposed to run in another thread. The null assignment would free memory insofar as it enables garbage collection of whatever was refered if it's the last reference, except I guess it doesn't in this case because the final variable is still around (which he can't null because it's final, durr). I think it's fair to call that a small bug that's not really related to thinking that reference assignment is deep copying Edit: I would have bet that the threading stuff was introduced after the null assignment but the repos doesn't seem to go back far enough to tell. Vanadium fucked around with this message at 02:18 on Feb 17, 2012 |
# ? Feb 17, 2012 02:13 |
|
|
# ? Jun 7, 2024 07:00 |
|
Look Around You posted:I don't hate it but I like knowing whether or not calling a function will change it's arguments. That's the big thing about it for me. This is why Ritchie granted us the power to name functions.
|
# ? Feb 17, 2012 09:56 |
|
Zombywuf posted:This is why Ritchie granted us the power to name functions.
|
# ? Feb 17, 2012 10:18 |
|
JewKiller 3000 posted:Dereferencing a NULL pointer leads to the ubiquitous segmentation fault. ctz posted:No it doesn't. The behaviour is undefined. Good exploitation vector.
|
# ? Feb 18, 2012 02:47 |
|
I would love to see a C implementation where the undefined behavior was things like "changes your desktop wallpaper to a picture of dogs playing poker" instead of just crashing.
|
# ? Feb 18, 2012 03:13 |
|
Kelson posted:CTZ is absolutely correct. Just to add a bit practically though, with x86 C/C++ dereferencing the NULL pointer is the same as dereferencing address 0x0. This is typically an invalid address, which causes JewKiller's seg fault. One can map memory to the NULL page in Windows however, which makes address 0 "valid." Even if the page containing 0x0 is invalid, dereferencing an invalid pointer can still do other things besides crash. Consider: code:
So, yeah, undefined behavior is undefined.
|
# ? Feb 18, 2012 03:20 |
|
Vanadium posted:Edit: I would have bet that the threading stuff was introduced after the null assignment but the repos doesn't seem to go back far enough to tell.
|
# ? Feb 18, 2012 04:55 |
|
GrumpyDoctor posted:I would love to see a C implementation where the undefined behavior was things like "changes your desktop wallpaper to a picture of dogs playing poker" instead of just crashing. http://www.feross.org/gcc-ownage/
|
# ? Feb 18, 2012 12:12 |
|
GrumpyDoctor posted:I would love to see a C implementation where the undefined behavior was things like "changes your desktop wallpaper to a picture of dogs playing poker" instead of just crashing. Still waiting on the canonical "demons fly out of your nose" implementation.
|
# ? Feb 18, 2012 18:48 |
|
Ah yes, the Armed Response Technologies Deathstation 9000.
|
# ? Feb 18, 2012 18:59 |
|
GrumpyDoctor posted:I would love to see a C implementation where the undefined behavior was things like "changes your desktop wallpaper to a picture of dogs playing poker" instead of just crashing. I'd love to see a pedagogical C/C++ implementation that goes to great lengths of runtime support and everything to give precise diagnostics for every bit of undefined (or implementation-defined, where the standard gives the implementation room to crash) behavior. It'd be great for arguing about dumb language-lawyery bullshit on IRC.
|
# ? Feb 18, 2012 20:18 |
|
Was using 'eor' as your mnemonic for 'exclusive or' as retarded in 1983 as it seems now?
|
# ? Feb 18, 2012 20:55 |
|
Vanadium posted:I'd love to see a pedagogical C/C++ implementation that goes to great lengths of runtime support and everything to give precise diagnostics for every bit of undefined (or implementation-defined, where the standard gives the implementation room to crash) behavior. It'd be great for arguing about dumb language-lawyery bullshit on IRC. Let's goon project this poo poo We have a couple of people itt that work or have worked on clang, right
|
# ? Feb 18, 2012 20:59 |
|
hobbesmaster posted:Was using 'eor' as your mnemonic for 'exclusive or' as retarded in 1983 as it seems now? I don't know about other processors, but the official name of the exclusive or op on the 6502 family was "eor". I learned to code on the C64 and got used to "eor" in the assemblers there, so when I first saw the "xor" spelling, I thought that was weird. (I prefer it now though.)
|
# ? Feb 18, 2012 23:09 |
|
hobbesmaster posted:Was using 'eor' as your mnemonic for 'exclusive or' as retarded in 1983 as it seems now? xor just like xml are right there in the same league of marketing bullshit "X sounds so far-out, man!" Xtreme programming anyone?
|
# ? Feb 19, 2012 01:02 |
|
Vanadium posted:I'd love to see a pedagogical C/C++ implementation that goes to great lengths of runtime support and everything to give precise diagnostics for every bit of undefined (or implementation-defined, where the standard gives the implementation room to crash) behavior. It'd be great for arguing about dumb language-lawyery bullshit on IRC.
|
# ? Feb 19, 2012 01:26 |
|
PrBacterio posted:I'm fairly sure this program exists and is called "valgrind" though? Does that blow up on things like assigning a size_t to an int?
|
# ? Feb 19, 2012 02:17 |
|
ICC would probably be sufficient for that, it whines like crazy.
|
# ? Feb 19, 2012 02:37 |
|
Jabor posted:Does that blow up on things like assigning a size_t to an int?
|
# ? Feb 19, 2012 03:09 |
|
PrBacterio posted:Probably there exists some tool for valgrind to make it blow up if the conversion fails due to overflow, though. This is impossible, there's no information at runtime about whether a value's supposed to be signed or unsigned, or that a truncation conversion is happening.
|
# ? Feb 19, 2012 04:49 |
|
Also there will never be a tool for valgrind though that flags if (size > size+1) {...} as dead code and gives a warning explaining why
|
# ? Feb 19, 2012 04:49 |
|
Otto Skorzeny posted:Also there will never be a tool for valgrind though that flags if (size > size+1) {...} as dead code and gives a warning explaining why Because it's not dead if size = INT_MAX?
|
# ? Feb 19, 2012 06:59 |
|
Overflow on signed ints is undefined, so the compiler is free to assume that condition is always false.
|
# ? Feb 19, 2012 07:01 |
|
HORATIO HORNBLOWER posted:Still waiting on the canonical "demons fly out of your nose" implementation.
|
# ? Feb 19, 2012 07:47 |
|
yaoi prophet posted:Because it's not dead if size = INT_MAX? Nope "LLVM's project blog post about this posted:Lets look at an example. Consider this carefully written C code: Nb. if you write a simple loop to test this you'll find that real live compilers do indeed perform this optimization.
|
# ? Feb 19, 2012 08:21 |
|
Do people really use if(size > size + 1) instead of if(size == INT_MAX)? The second seems clearer and avoids the optimization issue. Or is this just for the sake of the example?
|
# ? Feb 19, 2012 08:27 |
|
The usual (wrong) example is if (p + SOME_SIZE < p).
|
# ? Feb 19, 2012 09:25 |
|
xf86enodev posted:xor just like xml are right there in the same league of marketing bullshit "X sounds so far-out, man!" Sometimes its hard to tell if people are joking, but I've only ever seen XOR in my logic textbooks... it really doesn't matter but I have this twitch whenever I use ARM assembly.
|
# ? Feb 19, 2012 12:54 |
|
hobbesmaster posted:Sometimes its hard to tell if people are joking, but I've only ever seen XOR in my logic textbooks... it really doesn't matter but I have this twitch whenever I use ARM assembly. ARM is a British-designed ISA. We don't cotton to xtreme letterz as much as you lot
|
# ? Feb 19, 2012 17:55 |
|
Otto Skorzeny posted:Nope C only goes fast because compilers are allowed to write code that doesn't do what you wanted.
|
# ? Feb 19, 2012 18:06 |
|
In the same sense that C is considered a "simple" language because nobody knows how compilers actually handle it.
|
# ? Feb 19, 2012 18:20 |
|
Incidentally, clang already does have a -fcatch-undefined-behavior flag, and John Regehr (equivocation incoming) has had at least one student at some point in the past working on extending it. So some of this is already done. The really tricky part of catching all undefined behavior would be not integer overflow but things that rely on the effective type of an object, like the union type-punning rules and the aliasing rules. You'd need some sort of crazy side-table to avoid breaking ABI. (and yes, I am employed to work on clang full-time)
|
# ? Feb 19, 2012 20:17 |
|
rjmccall posted:like the union type-punning rules I thought the rules were 'just' that this wasn't allowed, eg. a read of type A from union {A, B} foo is only allowed if the last write to foo was of type A?
|
# ? Feb 19, 2012 20:33 |
|
Otto Skorzeny posted:I thought the rules were 'just' that this wasn't allowed, eg. a read of type A from union {A, B} foo is only allowed if the last write to foo was of type A? iirc, C99 doesn't even guarantee that integers are represented by two's complement. Scaevolus fucked around with this message at 21:07 on Feb 19, 2012 |
# ? Feb 19, 2012 21:01 |
|
Scaevolus posted:iirc, C99 doesn't even guarantee that integers are represented by two's complement. 1's complement and sign-magnitude are the other two options. Also it doesn't guarantee that all possible bit patterns are actually valid.
|
# ? Feb 19, 2012 23:33 |
|
Otto Skorzeny posted:I thought the rules were 'just' that this wasn't allowed, eg. a read of type A from union {A, B} foo is only allowed if the last write to foo was of type A? Pretty much, although there's an exception (in both C and C++) about structs with a common prefix.
|
# ? Feb 20, 2012 00:50 |
|
code:
|
# ? Feb 20, 2012 17:31 |
|
Haud posted:
I see that a lot, i think because code validators like PMD (in java) complain about code:
code:
|
# ? Feb 20, 2012 17:53 |
|
Jabor posted:1's complement and sign-magnitude are the other two options. There were actual real computers using non-twos-complement maths around when C became a Thing - http://en.wikipedia.org/wiki/CDC_6000_series http://en.wikipedia.org/wiki/IBM_7090 for example. There might even be some still knocking around with modern C compilers, for all I know; it makes sense the C people wouldn't want to rule out the possibility.
|
# ? Feb 20, 2012 18:40 |
|
|
# ? Jun 7, 2024 07:00 |
|
Is it cool to talk about terrible ideas here? Because a colleague/relation of mine had a brilliant idea to create a StackOverflow-type site, where the users post a poll with their question, "Which answer is right?". Other folks vote on that poll and by the Wisdom of the Group truth shall emerge and the best answer will win out, and those who voted for the correct answer get karma/rep for being right or just agreeing with the most people, which gives them more weight in any further polls they vote on. It would combine all the wisdom of Stack Overflow with the democracy of Reddit, in a final product that would, he assures me, make us zillions of dollars if I just do the backend work for him. Additional problems include the obvious fact that many users won't have a good idea as to what the truth is, and the old Put down the chocolate covered banana situations. I do like that phrase. Incidentally, this same dude thought the Unix Millennium bug could be solved by replacing the ints everywhere with doubles, because they have a larger range.
|
# ? Feb 20, 2012 19:08 |