Home » U++ TheIDE » U++ TheIDE: Compiling, Linking, Debugging of your packages » Linux .brc handling bug
Linux .brc handling bug [message #6396] |
Fri, 10 November 2006 14:13 |
zsolt
Messages: 698 Registered: December 2005 Location: Budapest, Hungary
|
Contributor |
|
|
I get "Segmentation fault" when trying to access a binary resource.
I gess that binary resources are compiling into code area and operating system does not allow access to it or the pointer points to a wrong address.
I tried reference/brc as well and it has this problem also.
Debugger stops at memcpy int the next method:
dword MemStream::_Get(void *data, dword size) {
if(size > (dword)(uintptr_t)(rdlim - ptr))
size = rdlim - ptr;
memcpy(data, ptr, size);
ptr += size;
return size;
}
|
|
|
|
|
|
|
|
|
Re: Linux .brc handling bug [message #7260 is a reply to message #6396] |
Tue, 19 December 2006 19:23 |
Balage
Messages: 17 Registered: December 2006
|
Promising Member |
|
|
And that works? It shouldn't
Taking the address of a char* results in char**, which you convert to const char*. It's only blind luck or coincidence I suppose why that doesn't crash big
EDIT: After reading the C FAQ, the reason why that doesn't crash, is that you take the address of a variable which holds a pointer, namely the address of std_tmpl_main[0].
This part of the library is awfully messy.
I've found someone else who also had this problem: http://cprogrammers.blogspot.com/2006/10/c-programming-diffe rent-signature.html
EDIT: I took a look at the C FAQ, and the exact problem is mentioned there (a VERY GOOD read): http://c-faq.com/aryptr/index.html
So I recommend to DON'T use the above code, but instead, use what produced the segfault, and fix the library.
[Updated on: Tue, 19 December 2006 20:12] Report message to a moderator
|
|
|
|
|
|
|
Re: Linux .brc handling bug [message #7276 is a reply to message #6396] |
Wed, 20 December 2006 00:06 |
Balage
Messages: 17 Registered: December 2006
|
Promising Member |
|
|
BINARY_MASK is also dangerous.
#define BINARY_MASK(i, m) \
extern "C" byte *i[]; \
extern "C" int COMBINE(i, _length)[]; \
extern "C" int COMBINE(i, _count); \
extern "C" char *COMBINE(i, _files)[];
The xxx_files part is generated like this:
char *xxx_files[] = {
"File1.cpp",
"File2.cpp",
};
That's an array of pointers, pointing to string literals. And string literals are const. So trying to modify xxx_files[i][n] also segfaults.
The solution is to either:
- Modify type to this: const char* xxx_files[]
(This also means to modify BINARY_MASK macro)
Or:
- Generate an array for each filename, then add those to xxx_files, like this:
static char xxx_file_1[] = "File1.cpp";
static char xxx_file_2[] = "File2.cpp";
char *xxx_files[] = {
xxx_file_1,
xxx_file_2,
};
Anyway, I also think that byte should be replaced with char, as that's what is used for the definition.
The current fix:
#define BINARY(i, f) \
extern "C" char i[]; \
extern "C" int COMBINE(i, _length);
#define BINARY_ARRAY(i, x, f) \
extern "C" char *i[]; \
extern "C" int COMBINE(i, _length)[]; \
extern "C" int COMBINE(i, _count);
#define BINARY_MASK(i, m) \
extern "C" char *i[]; \
extern "C" int COMBINE(i, _length)[]; \
extern "C" int COMBINE(i, _count); \
extern "C" const char *COMBINE(i, _files)[];
This makes types correct, so you don't accidentally segfault.
[Updated on: Wed, 20 December 2006 00:16] Report message to a moderator
|
|
|
Goto Forum:
Current Time: Sat May 04 10:19:45 CEST 2024
Total time taken to generate the page: 0.03409 seconds
|