|
Vanadium posted:Can you post the relevant parts of proj1 code:
code:
|
# ? Jan 28, 2009 00:15 |
|
|
# ? Apr 19, 2024 05:03 |
|
The ^@ are bytes with value 0. gedit does not know what the hell to do with them. Edit: The cin >> floors just reads the number, and leaves the newline in the stream. So the first getline makes temp an empty string. So reading temp[0], and later temp[i], is undefined behaviour. Vanadium fucked around with this message at 00:47 on Jan 28, 2009 |
# ? Jan 28, 2009 00:42 |
|
Vanadium posted:The ^@ are bytes with value 0. gedit does not know what the hell to do with them. I've never used it, but would cin.flush() get rid of the newline? edit: It seems to be reading that entire first line of the top row of the map as ^@. I've tried cin.flush() and cin.clear(), and neither of those do anything helpful. edit2: I added another getline right after I read in the two numbers, and before I started reading in the rest of the stuff, and that fixed it. That seems like a really crappy way to fix it though. Super Dude fucked around with this message at 02:27 on Jan 28, 2009 |
# ? Jan 28, 2009 02:04 |
|
You could use std::cin.ignore(std::numeric_limits<int>::max(), '\n'); instead of that getline, or you could just use std::getline in the first place instead of using operator>>, and then use std::strtol or something to read the numbers from the string. cin.flush() does not do anything that I am aware of, and cin.clear() clears the error bits, not the buffer or anything.
|
# ? Jan 28, 2009 02:42 |
|
Vanadium posted:You could use std::cin.ignore(std::numeric_limits<int>::max(), '\n'); instead of that getline, or you could just use std::getline in the first place instead of using operator>>, and then use std::strtol or something to read the numbers from the string. But getline grabs it as a string, right? I needed them to be ints.
|
# ? Jan 28, 2009 02:49 |
|
Super Dude posted:But getline grabs it as a string, right? I needed them to be ints. That is where strtol comes in.
|
# ? Jan 28, 2009 02:51 |
|
Vanadium posted:You could use std::cin.ignore(std::numeric_limits<int>::max(), '\n'); instead of that getline, or you could just use std::getline in the first place instead of using operator>>, and then use std::strtol or something to read the numbers from the string.
|
# ? Jan 28, 2009 05:35 |
|
Does the standard make any guarantees that I can allocate arrays of a certain size? Obviously at some point I am going to run into memory restrictions and I guess page sizes or whatever, but is there any defined minimum on allowed array sizes?
|
# ? Jan 28, 2009 16:15 |
|
I'm on Linux and I need to copy a temporary file to the working directory (via C++). I make the temporary file via mkstemp() and on my machine, it ends up in /tmp. My working directory is on the /home partition which differs from /tmp. When I tried using the system rename call, I got the error "Invalid cross-device link". So I tried using boost::filesystem but I'm getting the same error! Any suggestions? EDIT: I got it to work by using boost::filesystem::copy_file() followed by boost::filesystem::remove(). Bitruder fucked around with this message at 17:03 on Jan 28, 2009 |
# ? Jan 28, 2009 16:48 |
|
Bitruder posted:I'm on Linux and I need to copy a temporary file to the working directory (via C++). I make the temporary file via mkstemp() and on my machine, it ends up in /tmp. My working directory is on the /home partition which differs from /tmp. When I tried using the system rename call, I got the error "Invalid cross-device link". So I tried using boost::filesystem but I'm getting the same error! You can't rename a file from one filesystem to the other, you need to copy it if stat tells you the device # is different on the destination filesystem. There is no syscall that tries to rename and copies the contents if necessary
|
# ? Jan 28, 2009 16:59 |
|
Does anyone know of any good, preferably free, C++ IDEs that work for Vista? I tried CodeBlocks with the nightly builds and nothing happens when I try to build/run the program.
|
# ? Jan 28, 2009 19:51 |
|
shoe posted:Does anyone know of any good, preferably free, C++ IDEs that work for Vista? I tried CodeBlocks with the nightly builds and nothing happens when I try to build/run the program. Visual C++ Express?
|
# ? Jan 28, 2009 19:56 |
|
Thanks.
|
# ? Jan 28, 2009 20:06 |
|
I'm using the Xerces C++ XML parser, (the XercesDOMParser class) to parse a 60 meg xml file and I have a question. Here is the declaration of my parser: code:
Is there a more lightweight class I can use to parse this file without sacrificing too much in the speed department?
|
# ? Jan 28, 2009 21:52 |
|
You're probably going to have to use SAX (more like SUX) if you want to keep memory usage to a minimum.
|
# ? Jan 28, 2009 23:52 |
|
Vanadium posted:Does the standard make any guarantees that I can allocate arrays of a certain size? Obviously at some point I am going to run into memory restrictions and I guess page sizes or whatever, but is there any defined minimum on allowed array sizes?
|
# ? Jan 29, 2009 00:15 |
|
Thanks. I am somewhat disappointed, but I am not sure what I expected.
|
# ? Jan 29, 2009 00:42 |
|
Avenging Dentist posted:You're probably going to have to use SAX (more like SUX) if you want to keep memory usage to a minimum. Yea, SAX does suck, but it did the job well. I was able to reduce that jump in memory from by about 90%. Yay.
|
# ? Jan 29, 2009 02:06 |
|
Can anybody explain to me why the delete[] here causes a heap exception? uinfo is a struct, uinfo.xx is a char* and yy is a wchar_t*.code:
|
# ? Jan 29, 2009 14:31 |
|
Fehler posted:Can anybody explain to me why the delete[] here causes a heap exception? uinfo is a struct, uinfo.xx is a char* and yy is a wchar_t*. Edit: also wcslen() counts characters (not bytes) so if there's even one single character that requires two MBCS-encoded bytes then you'll overflow the uinfo.xx buffer. Standish fucked around with this message at 15:19 on Jan 29, 2009 |
# ? Jan 29, 2009 14:54 |
|
Thanks, I don't know what I was thinking when I wrote that. So what would be the best way to convert wchar_t to char in C++? I found "use_facet< ctype<wchar_t> >(loc).narrow(yy, yy+wcslen(yy), '?', uinfo.xx);" on Google, but that just causes the program to crash... Edit - Here is my code: code:
Fehler fucked around with this message at 16:10 on Jan 29, 2009 |
# ? Jan 29, 2009 15:28 |
|
Why are you messing around with dynamic memory Here is possibly useful code from a pal's hobby codebase: code:
|
# ? Jan 29, 2009 17:15 |
|
I'm confused about using shell scripts. Say I want a shell script that will have a command line "startscan inputdirectory outputdirectory", and it will just copy files from one to another How would I read that command line, and how would I work with it?
|
# ? Jan 29, 2009 23:20 |
|
mistermojo posted:I'm confused about using shell scripts. Say I want a shell script that will have a command line "startscan inputdirectory outputdirectory", and it will just copy files from one to another What does this have to do with C/C++?
|
# ? Jan 29, 2009 23:22 |
|
Avenging Dentist posted:What does this have to do with C/C++? i thought it used C? should I post this in another thread?
|
# ? Jan 29, 2009 23:26 |
|
mistermojo posted:i thought it used C? should I post this in another thread? Shell scripts are written in shell, which has almost nothing whatsoever to do with C or C++. You should probably post your question in the Linux thread.
|
# ? Jan 29, 2009 23:30 |
|
ShoulderDaemon posted:Shell scripts are written in shell, which has almost nothing whatsoever to do with C or C++. You should probably post your question in the Linux thread. What if you use the C shell (csh)?
|
# ? Jan 30, 2009 03:35 |
|
Ugg boots posted:What if you use the C shell (csh)? That was why I said "almost". It still belongs in the Linux thread, though.
|
# ? Jan 30, 2009 05:52 |
|
Today I spent most of my day trying to pin down a segfault caused by an fstream::write(). Stack traces say it's consistently caused inside the write() by a failed malloc(), which means (since I'm not running out of memory) it's probably a heap corruption issue. A double delete or a delete instead of delete[] or vice versa or something. This is on a Solaris SPARC machine, so I had access to dbx, and with it the memleak checker and memory access reporting. In addition to using that for dynamic analysis, I've had the good old "step through the debugger and try to remember when poo poo's been freed." I've been told there's also 'lint' or something like that for static analysis, but it doesn't seem to be on our dev machine. Or I'm not configured right, or something. But anyway. Have I missed any methods for tracking down memory corruption errors besides dbx, lint, and stepping? (if this continues much longer I swear to god I'm just gonna start changing every raw pointer into a boost::shared_ptr and I am only half kidding here, today loving sucked) Ciaphas fucked around with this message at 06:47 on Jan 30, 2009 |
# ? Jan 30, 2009 06:42 |
|
valgrind, cppcheck
|
# ? Jan 30, 2009 06:53 |
|
Ugg boots posted:What if you use the C shell (csh)?
|
# ? Jan 30, 2009 16:09 |
|
A followup question to yesterday's analysis question. In my quest to track down this loving malloc-in-an-fstream error, I stumbled on libumem, which is an alternate memory library for Solaris SPARC (which is my target and development system). Apparently the idea is that it runs normally, except that it coredumps on various forms of heap corruption (like double deletes especially). And it's apparently usable in production, too, not just dev. So I decided to use LD_PRELOAD load libumem instead of the default library, to get it to dump a more useful core when it breaks. The problem? It didn't break. The program finished execution, no signals, no errors, no coredumps, no nothing. And the output was exactly as expected. Stumped, I went back and reran the program without the LD_PRELOAD (so using the default allocator). Blam, blew up again. I'm kind of at a loss as to what's happening here. Does this mean the default allocation library has a bug in it, and my code was never buggy at all? Or that, perhaps, libumem is hiding the problem for some reason, and that I still have a heap corruption somewhere? What's the likely scenario? (I fully expect from well-learned pessimism that there is still a heap corruption going on and libumem is still masking it. But maybe there's hope yet.) Ciaphas fucked around with this message at 18:23 on Jan 30, 2009 |
# ? Jan 30, 2009 18:18 |
|
I seem to remember reading that some SPARC implementations don't like calls to delete 0, or free( 0 ), even those are allowed according to the standard. So that's probably the first thing to check. Second, a double-delete wouldn't be my first thought. If they're going to go, they usually (although not always) crash at the delete itself. A crash in a malloc is more often an indicator that an allocated buffer has been overrun, which means that any 'tags' used as headers and footers for allocations have been trashed just prior to the malloc that dies. How large is the codebase we're talking about?
|
# ? Jan 30, 2009 18:37 |
|
TSDK posted:I seem to remember reading that some SPARC implementations don't like calls to delete 0, or free( 0 ), even those are allowed according to the standard. So that's probably the first thing to check. Big enough that I spent the entire day yesterday combing for memory errors (and found a few) without finding the one that's causing the crash. Don't have a line count or anything like that handy (and in fact, while I'm on the internet here, I'm not at my work computer--security ), but at a guess call it about 40 classes of between 100 and 500 lines or so each getting executed in this particular run of the program (with heavy-duty amounts of looping), though I ended up checking the entire codebase by hand. Not much help, I know, sorry. Now that you mention it, though, I didn't test how libumem does on crashing when a buffer gets overrun, I only tested that it crashes on double deletes or deleting 0 (the default implementation doesn't crash on either). I'll have to check on that when I get back. Ciaphas fucked around with this message at 19:03 on Jan 30, 2009 |
# ? Jan 30, 2009 18:59 |
|
Really though, use valgrind
|
# ? Jan 30, 2009 19:10 |
|
Otto Skorzeny posted:Really though, use valgrind Not available on Solaris SPARC, or even Solaris x86 for that matter
|
# ? Jan 30, 2009 19:24 |
|
Ledneh posted:Not available on Solaris SPARC, or even Solaris x86 for that matter drat. A quick googling seems to indicate that on Solaris you can either spring for Purify(which by all accounts is very, very good on Solaris, much better than the Linux version of purify) or stick with umem and mdb.
|
# ? Jan 30, 2009 19:37 |
|
Ledneh posted:Not available on Solaris SPARC, or even Solaris x86 for that matter Writing your own memory verification wrapper wouldn't actually take all that long. Probably about a day. You'd need a local std::map< void *, size_t > to keep track of all currently allocated buffers and their corresponding sizes (and a flag to suppress the custom allocation behaviour when you're adding to the internal map). When calling through to the __real_malloc, you allocate three times the normal size (or an appropriately large padding zone) and fill the buffer with a particular pattern before and after the actual pointer that you're returning. code:
A relatively simple scheme like that should pick up uninitialised memory, deleting invalid pointers, using pointers after they've been free'd, and corruption before and after a buffer.
|
# ? Jan 30, 2009 19:44 |
|
I think that's what libumem already does in debug mode (except the pads are 0xdeadbeef and 0xbaddcafe, for some reason ). But assuming libumem fails me, I'll try writing a wrapper like that. Pretty sure the compiler can handle that. Speaking of which, I turned on more strict debug options in libumem and it found some more invalid deletes, so I'm waiting now for a recompile and rerun. We'll see if those were the ones or not, I guess. Also, we might have Purify since we use ClearCase, but if we do it's not installed on our dev server. I'll bug our license guy when he gets back after the weekend, assuming I haven't solved this by then. (EDIT) Think I found it--it ran through all the way but I have to test some more. There's a bit of code that looks something like this: code:
code:
Ciaphas fucked around with this message at 20:52 on Jan 30, 2009 |
# ? Jan 30, 2009 20:39 |
|
|
# ? Apr 19, 2024 05:03 |
|
Ledneh posted:Now, correct me if I'm wrong, but I thought you were supposed to use delete[] on anything made with new[], even if the array size is 1. If that's true, does that mean the program ran this time due only to the power of Undefined Behavior(®)? And if that was false... then what the flipping gently caress is wrong with the Sun C++ compiler?!
|
# ? Jan 30, 2009 20:56 |