Live Chat & Podcast at 1:00PM Eastern on Sunday!
There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
Search
Tag Cloud
access acer asus batch bios bsod computer crash desktop driver drivers error ethernet excel freeze gaming hard drive hardware hdmi internet laptop malware memory modem monitor motherboard mouse network printer problem ram registry router slow software sound trojan ubuntu 11.10 uninstall usb video virus vista wifi windows windows 7 windows 7 32 bit windows 7 64 bit windows xp wireless
Search
Search for:
Tech Support Guy Forums > Software & Hardware > Software Development >
Solved: char* p = "string" == page fault?

Reply  
Thread Tools
mt2002's Avatar
Computer Specs
Senior Member with 926 posts.
 
Join Date: Sep 2005
Location: 127.0.0.1
Experience: Advanced
24-Nov-2008, 11:16 PM #1
Solved: char* p = "string" == page fault?
Hey everyone,

What exactally happens when you let the compiler assign a string buffer to a pointer? ie: char* p = "Hello, world!"; but assigning the string from a superclass to a subclass pointer? Are they both handled the same?

I have the following code:

Code:
class cmd_title : public internal_cmd {

public:

	cmd_title () {

		m_flags=BUILTIN_CMDLINE|BUILTIN_HELP_LIST;
		m_name="title";
		m_doc="title [NAME]\n\r\Add a new boot entry";		//invalid instruction??
	}

	virtual	int callback (char* cmd, int parms) {

		core* p = core::get();

		if (p)
			p->get_bios()->puts ("\n\r%s", m_doc);

		return 0;
	};
};
m_doc is simply a char* declared in the base class internal_cmd. The above code seems to either page fault or cause an invalid instruction when m_doc is displayed (The call to puts() ).

An interesting thing to note is, if I shorten the m_doc string by so much it gets displayed fine and works. What is more interesting is that it will only cause a problem if I display it which has me somewhat lost.

Does anyone know what can cause this to happen? I can probably get this working if I declare m_doc as a static array, but I am curious about this one

Please keep in mind this is running in ring 0 (supervisor mode).

This makes me worried so I decided to post here to see what others ideas are. Thanks for any input
__________________
char c[3]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
mt2002's Avatar
Computer Specs
Senior Member with 926 posts.
 
Join Date: Sep 2005
Location: 127.0.0.1
Experience: Advanced
25-Nov-2008, 12:26 AM #2
I decided to not store the description string (the m_doc pointer) and just do it manually via p->get_bios()->puts ("string"); and it worked fine.

Im still unsure of why I could not store or work with any static string passed to puts() (That is, the following crashed the same way) :

Code:
static char* t = "test long string";
p->get_bios()->puts ("%s", t);
But it works fine in any other part of the code and if I do the above manually rather then storing it. Weird.

Im going to mark this solved sense I found a solution but I still am open for possible suggestions for what can cause something like this to happen...
__________________
char c[3]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
Reply

THIS THREAD HAS EXPIRED.
Are you having the same problem? We have volunteers ready to answer your question, but first you'll have to join for free. Need help getting started? Check out our Welcome Guide.

Search Tech Support Guy

Find the solution to your
computer problem!




Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
WELCOME TO TECH SUPPORT GUY! Are you looking for the solution to your computer problem? Join our site today to ask your question -- for free! Our site is run completely by volunteers who want to help you solve your computer problems. See our Welcome Guide to get started.
Thread Tools



Facebook Facebook Twitter Twitter TechGuy.tv TechGuy.tv Mobile TSG Mobile
You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -4. The time now is 01:42 AM.
Copyright © 1996 - 2011 TechGuy, Inc. All rights reserved.

Powered by Cermak Technologies, Inc.