473,504 Members | 13,746 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

stack corrupted around the variable

1 New Member
hi,
i m using VC++8.0 MFC. i m facing the problem atack corrupt around the variable stCmosPortInput.
i am reading some information from ini file.information is as following format.

//Setting_1 = Floppy Drive Type,0x71,0x10,0x03,0x40;

for each comma serated information i am filling structure.

code for reading ini fileis as follows.


Expand|Select|Wrap|Line Numbers
  1. FILE    *pDefinitionFile;
  2.     CString szTempMsg = _T("");
  3.     CString szErrMsg = _T("");
  4.     //IOREGSETINPUT    stIORegSetInput = {0};
  5.     CMOSPORTINPUT    stCmosPortInput = {0};
  6.  
  7.     int nIndex = 0;        // index of searched string
  8.     int nCount = 0;        //no. of entries in structure.
  9.     int nNoOfBiosSettings = 0;
  10.  
  11.     CHAR szDefinitionFile[MAX_PATH] = {0};    
  12.     CHAR szTempFileBuffer[256] = {0};
  13.  
  14.     CString szFileData = _T("");    
  15.     CString szBiosSettings = _T("");    
  16.     CString szBiosSettingName = _T("");
  17.     CString szIOPort = _T("");            
  18.     CString szOffSet = _T("");            
  19.     CString szMaskValue = _T("");        
  20.     CString szExpectedValue = _T("");    
  21.     CString szTempSettings = _T("");  
  22.  
  23.     m_listBiosSettings.RemoveAll();
  24.  
  25.  
  26.     PerformMessageLogging("Getting values from INI file");
  27.     ZeroMemory(szDefinitionFile,sizeof(szDefinitionFile));
  28.     GetCurrentDirectory(MAX_PATH,szDefinitionFile);
  29.  
  30.     szDefinitionFile[lstrlen(szDefinitionFile)-3] = 'e';
  31.     szDefinitionFile[lstrlen(szDefinitionFile)-2] = 'n';
  32.     szDefinitionFile[lstrlen(szDefinitionFile)-1] = 'v';
  33.     szDefinitionFile[lstrlen(szDefinitionFile)] = '\\';
  34.     szDefinitionFile[lstrlen(szDefinitionFile)] = '\0';
  35.  
  36.     strcat_s(szDefinitionFile,INI_FILE_NAME);
  37.     errno_t fileErr;
  38.     fileErr = fopen_s(&pDefinitionFile, szDefinitionFile, "r");
  39.     if(fileErr != 0)
  40.     {
  41.         szTempMsg.LoadString(IDS_ERR_INIFILE);
  42.         szErrMsg.Format(szTempMsg,szDefinitionFile);
  43.  
  44.         ErrorAndTraceHandler(SOFTWARE_ERR,
  45.                                     FALSE,
  46.                                     IDS_FUN_READINIFILE,
  47.                                     OCR_FILE_ERROR,
  48.                                     IDS_API_FOPEN,
  49.                                     IDS_ERR_INIFILE,
  50.                                     fileErr);
  51.  
  52.     }
  53.  
  54.     while(TRUE)
  55.     {
  56.     if(fgets(szTempFileBuffer,sizeof szTempFileBuffer),pDefinitionFile)!= NULL)
  57.     {
  58.  
  59.     szFileData = szTempFileBuffer;
  60.  
  61.     if(szFileData.Left(1) == "#")
  62.     {
  63.     continue;
  64.                 }
  65.     //e.g. if BIOS setting given in ini file is as following 
  66.     //Setting_1 = Floppy Drive Type,0x71,0x10,0x03,0x40;
  67.  
  68.     PerformMessageLogging(szFileData);
  69.     nNoOfBiosSettings++;
  70.     CString csTemp = _T("");
  71.     nIndex = szFileData.ReverseFind('=');
  72.     szBiosSettings = szFileData.Mid(nIndex+1);
  73.     nIndex = szBiosSettings.Find(";");
  74.     csTemp = szBiosSettings.Left(nIndex);
  75.  
  76.     m_csArrIniFileData.Add(csTemp);
  77.     PerformMessageLogging(csTemp);
  78.  
  79.     nIndex = 0;
  80.     szBiosSettingName = _T("");
  81.     nIndex = szBiosSettings.Find(',',0);
  82.     szBiosSettingName = szBiosSettings.Left(nIndex);
  83.     stCmosPortInput.szSettingName = szBiosSettingName;
  84.  
  85.     PerformMessageLogging(szBiosSettingName);
  86.     // separate string after occurence of first ','
  87.     szTempSettings = szBiosSettings.Mid(nIndex+1);
  88.     // Read I/O Port before second comma
  89.     CString szTemp = _T("");
  90.     LPTSTR BiosTMP = NULL;
  91.     nIndex = 0;
  92.  
  93.     nIndex = szTempSettings.Find(',',0);
  94.     szIOPort = szTempSettings.Left(nIndex);
  95.     BiosTMP = szIOPort.GetBuffer(szIOPort.GetLength()+1);
  96.         szIOPort.ReleaseBuffer();
  97.             //Store hexadecimal value into decimal format
  98.             //sscanf_s(BiosTMP, "%i", &(stCmosPortInput.ucReadPortAddr));
  99.             sscanf_s(BiosTMP, "%x", &(stCmosPortInput.ucReadPortAddr));
  100.  
  101.             csTemp.Format("I/O PortAddress in decimal format = %u",stCmosPortInput.ucReadPortAddr);
  102.             PerformMessageLogging(csTemp);
  103.  
  104.  
  105.  
  106.             // Separate string after occurence of second ','
  107.             szTemp = szTempSettings.Mid(nIndex+1);
  108.  
  109.             //Read Offset of setting before third comma
  110.             nIndex = 0;
  111.             BiosTMP = NULL;
  112.             nIndex = szTemp.Find(',',0);
  113.             szOffSet = szTemp.Left(nIndex);
  114.             BiosTMP = szOffSet.GetBuffer(szOffSet.GetLength()+1);
  115.             szOffSet.ReleaseBuffer();
  116.             //sscanf_s(BiosTMP, "%i", &(stCmosPortInput.ucOffset));
  117.             sscanf_s(BiosTMP, "%x", &(stCmosPortInput.ucOffset));
  118.  
  119.             csTemp = _T("");
  120.             csTemp.Format("Offset = %u",stCmosPortInput.ucOffset);
  121.             PerformMessageLogging(csTemp);
  122.  
  123.             // Separate string after occurence of third ','
  124.             szTempSettings = _T("");
  125.             szTempSettings = szTemp.Mid(nIndex+1);
  126.  
  127.             // Read Mask Value before fourth comma
  128.             nIndex = 0;
  129.             BiosTMP = NULL;
  130.             nIndex = szTempSettings.Find(',',0);
  131.             szMaskValue = szTempSettings.Left(nIndex);
  132.             BiosTMP = szMaskValue.GetBuffer(szMaskValue.GetLength()+1);
  133.             szMaskValue.ReleaseBuffer();
  134.             //sscanf_s(BiosTMP, "%i", &(stCmosPortInput.ucMaskValue));
  135.             sscanf_s(BiosTMP, "%x", &(stCmosPortInput.ucMaskValue));
  136.  
  137.             csTemp =_T("");
  138.             csTemp.Format("Mask Value = %u",stCmosPortInput.ucMaskValue);
  139.             PerformMessageLogging(csTemp);
  140.  
  141.             // Separate string after occurence of Fourth ','
  142.             szTemp = _T("");
  143.             szTemp = szTempSettings.Mid(nIndex+1);
  144.  
  145.             // Read Expected Value before ;
  146.             nIndex = 0;
  147.             BiosTMP = NULL;
  148.             nIndex = szTemp.ReverseFind(';');
  149.             szExpectedValue = szTemp.Mid(0,nIndex);
  150.             BiosTMP = szExpectedValue.GetBuffer(szExpectedValue.GetLength()+1);
  151.             szExpectedValue.ReleaseBuffer();
  152.             //sscanf_s(BiosTMP, "%i", &(stCmosPortInput.ucExpectedValue));
  153.             sscanf_s(BiosTMP, "%x", &(stCmosPortInput.ucExpectedValue));
  154.  
  155.             csTemp =_T("");
  156.             csTemp.Format("Expected Value = %u",stCmosPortInput.ucExpectedValue);
  157.             PerformMessageLogging(csTemp);
  158.             //PerformMessageLogging("end of setting");
  159.  
  160.             m_listBiosSettings.AddTail(stCmosPortInput);
  161.             //AddDataToList(&stCmosPortInput);
  162.             //nCount++;
  163.         }
  164.         else
  165.         {
  166.             m_nSettingCount = nNoOfBiosSettings;
  167.             break;
  168.         }
  169.     }
  170.     fclose(pDefinitionFile);
  171.     PerformMessageLogging("Values extracted from INI file");
  172.  
  173.     if(m_nSettingCount == 0)
  174.     {
  175.         PerformMessageLogging("BIOS settings not found in INI file");
  176.         //szErrMsg.Format("%s",INI_FILE_NAME);
  177.  
  178.         ErrorAndTraceHandler(COMMON_ERR,
  179.                                     FALSE,
  180.                                     IDS_FUN_READINIFILE,
  181.                                     OCR_FILE_ERROR,
  182.                                     0,
  183.                                     IDS_ERR_NOSETTING,
  184.                                     0);
  185.  
  186.     }
Feb 15 '07 #1
0 1613

Sign in to post your reply or Sign up for a free account.

Similar topics

5
10189
by: Ilia Poliakov | last post by:
I have a static function in the class like this: class A { static void f1() } void A::f1() { .....
0
1021
by: Jeffrey Baker | last post by:
Hello, This is probably overkill - I tried to run a program with the i/o putting more data in, then the compiler is allowed to use. FYI - "Run-Time Check Failure #2 - Stack around the variable...
2
2466
by: news.tkdsoftware.com | last post by:
Aside from comp.compilers, is there any other forum, newsgroup or medium where I can post questions concerning the development of a byte code compiler & virtual stack machine? --
3
6232
by: Jeffrey Baker | last post by:
Hi, I am recompiling a program from VC++ 5.0 to VC++.NET interface. C++ Compliance is tighter. I get the error message before the program finished that stack corrupt around "obj". - this being...
19
3110
by: Jim | last post by:
I have spent the past few weeks designing a database for my company. The problem is I have started running into what I believe are stack overflow problems. There are two tab controls on the form...
5
1696
by: Al | last post by:
Hi Folks, I am getting : RunTime Check Failure #2 - Stack around the variable nPortNumber was corrupted on line : pMT->MT_SetCOMPort(nPortNumber);
4
2664
by: catherineod | last post by:
Hi, could anyone help me with this problem? I'm getting the following error message when I try to run this code - "Run-Time Check Failure #2 - Stack around the variable 'vY' was corrupted" Where am...
7
2146
by: ifoundgoldbug | last post by:
Ok here is a short description of what i am doing. I need to program a dll for use by another program. the dll compiles fine but when i call it from another program i get a stack corruption of...
4
2112
by: Hypnotik | last post by:
Hello everyone. I'm working on a program that crashes whenever I enter the value that is supposed to stop the program. The program takes in various pieces of info, has a struct and a class. The...
0
7213
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7098
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7298
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7366
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7017
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7471
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
4698
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
1526
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
754
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.