n00b completely stumped...

I am trying to get back into C++, after a LONG stint away..
In doing so I am starting with a project to get a bbs software up and running again.

I have been trying to understand why, it keeps seg faulting when it tries to use a string entered into a box..

<snip>
UIInputBox *pwInput = new UIInputBox(desktop, 5, 40, 0, 0, "Enter system password:", "Authentication", "*");
pwInput->Run();
std::string entered = pwInput->GetText();
</snip>

The application seg faults here.. " std::string entered = pwInput->GetText();"

I can't make any sense of it, what so ever, can anyone please offer up some advice on this?

The full source tree is available at http://wwiv.sourceforge.net/ , the svn command is svn co https://wwiv.svn.sourceforge.net/svnroot/wwiv wwiv .

The source file I am trying to build is in wwiv/trunk/bbs/init/main.cpp

ANY assistance would be greatly appreciated.

Thanks in advance.

J

P.S.

The full source to main.cpp is below ..

<source>
/**************************************************************************/

/* */

/* WWIV Version 5.0x */

/* Copyright (C)1998-2007, WWIV Software Services */

/* */

/* Licensed under the Apache License, Version 2.0 (the "License"); */

/* you may not use this file except in compliance with the License. */

/* You may obtain a copy of the License at */

/* */

/* http://www.apache.org/licenses/LICENSE-2.0 */

/* */

/* Unless required by applicable law or agreed to in writing, */

/* software distributed under the License is distributed on an */

/* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, */

/* either express or implied. See the License for the specific */

/* language governing permissions and limitations under the License. */

/* */

/**************************************************************************/



#define _DEFINE_GLOBALS_

#include "wwiv.h"

#undef _DEFINE_GLOBALS_

#include <iostream>

#include "TextUI.h"



#include "sys_general.h"

#include "sys_paths.h"



class ExitCommand : public UICommand

{

virtual bool Execute()

{

UIDesktop::GetDesktop()->TerminateApplication( 0 );

return true;

}

};



class InfoCommand : public UICommand

{

virtual bool Execute()

{

UIDesktop *desktop = UIDesktop::GetDesktop();

UIMessageBox infoWindow( desktop, 10, 40, 5, 20, true );

infoWindow.AddText( "WWIV Init", true );

infoWindow.AddText( "" );

infoWindow.AddText( "Copyright (c) 2007 WWIV Software Services", true );

infoWindow.AddText( "All Rights Reserved", true );

infoWindow.AddText( "http://wwiv.sourceforge.net", true );

infoWindow.SetTitle( "WWIV Init" );

infoWindow.Run();

return true;

}

};



void CreateMenus( UIMenuBar* menuBar )

{

UIMenu *fileMenu = new UIMenu( "File" );

fileMenu->Add( new UIMenuItem ( "Exit", new ExitCommand ) );

menuBar->AddMenu( fileMenu );

UIMenu *systemMenu = new UIMenu( "System" );

systemMenu->Add(new UIMenuItem( "General", new SystemGeneral ) );

systemMenu->Add(new UIMenuItem( "Paths", new SystemPaths ) );

systemMenu->Add(new UIMenuItem( "Networks", NULL ) );

menuBar->AddMenu( systemMenu );

UIMenu *optionsMenu = new UIMenu( "Options" );

optionsMenu->Add(new UIMenuItem( "External Editors", NULL ) );

optionsMenu->Add(new UIMenuItem( "Xfer protocols", NULL ) );

optionsMenu->Add(new UIMenuItem( "Archivers", NULL ) );

optionsMenu->Add(new UIMenuItem( "Security levels", NULL ) );

optionsMenu->Add(new UIMenuItem( "Auto-Validation", NULL ) );

menuBar->AddMenu( optionsMenu );

UIMenu *modemMenu = new UIMenu( "Modem" );

modemMenu->Add(new UIMenuItem( "Port(s)", NULL ) );

modemMenu->Add(new UIMenuItem( "Auto-detect", NULL ) );

menuBar->AddMenu( modemMenu );

}



int main( int argc, char* argv[] )

{

UIDesktop* desktop = UIDesktop::InitializeDesktop( true, true );

UISubWindow *window = new UISubWindow( desktop, 6, 50, 10, 15, UIColors::BACKGROUND_TEXT_COLOR, false );



std::string name(" WWIV Init ");

name += wwiv_version;

name += " ";

name += beta_version;

name += " ";

window->WriteCentered( 1, name );

window->WriteCentered( 3, " Copyright (c) 2007 WWIV Software Services. " );

window->WriteCentered( 5, " All Rights Reserved. " );



WFile configFile( CONFIG_DAT );

int nFileMode = WFile::modeReadOnly | WFile::modeBinary;

if ( configFile.Open( nFileMode ) )

{

configFile.Read( &syscfg, sizeof( configrec ) );

configFile.Close();

UIInputBox *pwInput = new UIInputBox(desktop, 5, 40, 0, 0, "Enter system password:", "Authentication", "*");

pwInput->Run();

std::string entered = pwInput->GetText();

/* if(!wwiv::stringUtils::IsEqualsIgnoreCase(syscfg.systempw, entered.c_str()))

{

UIMessageBox msgBox(desktop, 8, 40, 5, 20, true);

msgBox.AddText("System password does not match", true);

msgBox.Run();

delete pwInput;

delete window;

delete desktop;

exit(-1);

}

delete pwInput;

}

else

{

UIInputBox *pwInput = new UIInputBox(desktop, 5, 40, 0, 0, "Enter new system password:", "Authentication");

pwInput->Run();

memset( &syscfg, 0, sizeof( configrec ) );

strcpy(syscfg.systempw, pwInput->GetText().c_str());

int nFileMode = WFile::modeCreateFile | WFile::modeReadWrite | WFile::modeBinary;

if ( configFile.Open( nFileMode ) )

{

configFile.Write( &syscfg, sizeof( configrec ) );

configFile.Close();

UIMessageBox box(desktop, 5, 40, 0, 0);

box.WriteCentered(1, "Created new SYSTEM.DAT");

box.Run();

}

delete pwInput;*/

}



CreateMenus( desktop->GetMenuBar() );



desktop->Paint();

desktop->RunLoop();

delete window;

delete desktop;



nFileMode = WFile::modeReadWrite | WFile::modeBinary;

configFile.Open( nFileMode );

configFile.Write( &syscfg, sizeof( configrec ) );

configFile.Close();

return 0;

}

</source>
Last edited on
I'm not 100% sure, but I believe you got a segmentation fault due to a memory leak. You commented out a bunch of lines after the one giving you that error, and one of those lines was when you deleted the password object. Try either uncommenting it, or add another call to delete to see if it fixes your error.
I have tried what you suggested, I took it even further...

I went into the source files for the UIINputBox and added printf("blah blah line blah\n"); So I could get an idea of where the code is when it dies..
The bottom line, weather I comment out all the lines you spoke of or not, if "std::string entered = pwInput->GetText();" exists below pwInput->Run(); , it screws something up completely...

I have tried it so many different ways, I am pulling my hair out at this point.. I do not understand how the GetText can interfere with the previous line of code? I mean, before it even gets done executing, it kills it with a segfault.. If I have the GetText line in place and functional, it seems to blow up a statement of code BEFORE it actually executes..


Example..
gdb output..

│106 printf("Executing pwInput->Run();\n");
(gdb) │
107 pwInput->Run();
Program received signal SIGSEGV, Segmentation fault.

0x00007ffff7d770e3 in std::basic_string<char, std::char_traits<char>, std::allocator<char> >::length() const () from /usr/lib64/libstdc++.so.

The actual code..

UIInputBox *pwInput = new UIInputBox(desktop,5,40,0,0,"Enter system password:","Authentication","*");
printf("Executing pwInput->Run();\n");
pwInput->Run();
printf("Finished exexcuting pwInput->Run();\n");
printf("Exexcuting std::string result = pwInput-> GetText();\n");
std::string result = pwInput-> GetText();

On top of the printf strings in that cpp file, I have similar ones in the source for the InputBox.cpp that do not get printed if I have that GetText following the pwInput->Run(); It'a amazingly impossible..

If I take that GetText line out, it hits all the printf statements in my modified source files.. I am just lost..

J
Have you ever had an issue with a UI InputBox before? It looks like that is what is causing the seg fault. Aside from looking into the class methods themselves, I'd say there is nothing wrong with your code, but I'm far from being considered an expert.
Topic archived. No new replies allowed.