Skip to content
Snippets Groups Projects
Commit f2985366 authored by gatsjanos's avatar gatsjanos
Browse files

Offl heap corruption kijavitva (hibás "string" struct kezeles okozta) --> nezd...

Offl heap corruption kijavitva (hibás "string" struct kezeles okozta) --> nezd meg ezt az Online lognal is
parent c4c08c68
No related branches found
No related tags found
No related merge requests found
Showing
with 64 additions and 22 deletions
No preview for this file type
File suppressed by a .gitattributes entry, the file's encoding is unsupported, or the file size exceeds the limit.
No preview for this file type
No preview for this file type
/*
!!!!MINDIG x86-ra buildelj! A MySQl connector nem mkdik 64 biten.!!!!
*/
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
...@@ -5,7 +10,7 @@ ...@@ -5,7 +10,7 @@
#include <time.h> #include <time.h>
#include <float.h> #include <float.h>
#include <math.h> #include <math.h>
#include <dirent.h> #include "3rdparty\dirent.h"
#include "3rdparty/mysql-connector-c-6.1.11-win32\include\mysql.h" #include "3rdparty/mysql-connector-c-6.1.11-win32\include\mysql.h"
#include "3rdparty\curl-7.56.0\builds\libcurl-vc-x86-release-dll-ipv6-sspi-winssl\include\curl\curl.h" #include "3rdparty\curl-7.56.0\builds\libcurl-vc-x86-release-dll-ipv6-sspi-winssl\include\curl\curl.h"
char IsNaN(float f) char IsNaN(float f)
...@@ -223,14 +228,24 @@ void EszkozTombNoveles(int proba) ...@@ -223,14 +228,24 @@ void EszkozTombNoveles(int proba)
}*/ }*/
++EszkozokSzama; ++EszkozokSzama;
//if (EszkozokSzama == 1) return;
// Make the array bigger // Make the array bigger
EszkozokBuffer = realloc(Eszkozok, EszkozokSzama * sizeof(Eszkoz)); EszkozokBuffer = realloc(Eszkozok, EszkozokSzama * sizeof(Eszkoz));
if (!EszkozokBuffer) { --EszkozokSzama; delay(10); EszkozTombNoveles(proba + 1); return; } if (!EszkozokBuffer) { --EszkozokSzama; delay(10); EszkozTombNoveles(proba + 1); return; }
Eszkozok = EszkozokBuffer; Eszkozok = EszkozokBuffer;
//init new element
Eszkozok[EszkozokSzama - 1].OsszMukodes = 0; Eszkozok[EszkozokSzama - 1].OsszMukodes = 0;
Eszkozok[EszkozokSzama - 1].OsszPihenes = 0; Eszkozok[EszkozokSzama - 1].OsszPihenes = 0;
Eszkozok[EszkozokSzama - 1].OsszNincsadat = 0; Eszkozok[EszkozokSzama - 1].OsszNincsadat = 0;
Eszkozok[EszkozokSzama - 1].OsszLogHossz = 0;
Eszkozok[EszkozokSzama - 1].Emelet = 0;
Eszkozok[EszkozokSzama - 1].Tipus = 0;
Eszkozok[EszkozokSzama - 1].MukodesArany = 0;
//printf_s("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\n"); //printf_s("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\n");
// Clean up when you're done. // Clean up when you're done.
...@@ -540,6 +555,7 @@ char *szambuff3; ...@@ -540,6 +555,7 @@ char *szambuff3;
char *szambuff4; char *szambuff4;
char *szambuff5; char *szambuff5;
char *szambuff6; char *szambuff6;
void EnumString(struct string s, char OnlineMode /*0: Offline, Ms: Online*/) void EnumString(struct string s, char OnlineMode /*0: Offline, Ms: Online*/)
{ {
int Emelet = -99999; int Emelet = -99999;
...@@ -667,7 +683,7 @@ void EnumString(struct string s, char OnlineMode /*0: Offline, M ...@@ -667,7 +683,7 @@ void EnumString(struct string s, char OnlineMode /*0: Offline, M
delay(30); delay(30);
printf("Creating row: %d %d %d %d -> ", l.Tipus, l.Emelet, l.Statusz, l.Hossz); printf("Creating row: Type: %d Floor: %d Status: %d Duration: %ds -> ", l.Tipus, l.Emelet, l.Statusz, l.Hossz);
if (SqlInsert(l) == 0) if (SqlInsert(l) == 0)
printf("Succeeded.\n"); printf("Succeeded.\n");
else else
...@@ -690,8 +706,11 @@ void EnumString(struct string s, char OnlineMode /*0: Offline, M ...@@ -690,8 +706,11 @@ void EnumString(struct string s, char OnlineMode /*0: Offline, M
Eszkozok[x].OsszPihenes += 5 * 60; Eszkozok[x].OsszPihenes += 5 * 60;
else if (l.Statusz == 1)//Aktv else if (l.Statusz == 1)//Aktv
Eszkozok[x].OsszMukodes += 5 * 60; Eszkozok[x].OsszMukodes += 5 * 60;
else //N/ else //N/A
Eszkozok[x].OsszNincsadat += 5 * 60; Eszkozok[x].OsszNincsadat += 5 * 60;
printf_s(" ==>Gathered data: Type: %d Floor: %d Status: %d\n", l.Tipus, Emelet, l.Statusz);
} }
} }
...@@ -704,6 +723,7 @@ struct string sEgyLog; ...@@ -704,6 +723,7 @@ struct string sEgyLog;
struct string xEgyLog; struct string xEgyLog;
void EgyLogKeszito() void EgyLogKeszito()
{ {
int dekodolthossz;
printf("Creating new log...\n============================\n"); printf("Creating new log...\n============================\n");
...@@ -724,7 +744,15 @@ void EgyLogKeszito() ...@@ -724,7 +744,15 @@ void EgyLogKeszito()
}*/ }*/
//x.len = 10000; //x.len = 10000;
xEgyLog.ptr = realloc(xEgyLog.ptr, sEgyLog.len * sizeof(char));//Ez biztosan nagyobb, vagy akkora, mint a dekdols utni karakterlnc
xEgyLog.len = utf8_to_latin9(xEgyLog.ptr, sEgyLog.ptr, sEgyLog.len); xEgyLog.len = utf8_to_latin9(xEgyLog.ptr, sEgyLog.ptr, sEgyLog.len);
//writefunc("ABCDEFABCDEF", dekodolthossz, 1, &xEgyLog);
//printf("INSTRING: %s", sEgyLog.ptr);
printf("EgyLogKeszito() 2\n"); printf("EgyLogKeszito() 2\n");
EnumString(xEgyLog, 1); EnumString(xEgyLog, 1);
...@@ -770,16 +798,17 @@ void Logolas() ...@@ -770,16 +798,17 @@ void Logolas()
curl_easy_setopt(curl, CURLOPT_URL, "http://mosogep.sch.bme.hu/index.php"); curl_easy_setopt(curl, CURLOPT_URL, "http://mosogep.sch.bme.hu/index.php");
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writefunc); curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writefunc);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &sEgyLog);
curl_easy_setopt(curl, CURLOPT_ENCODING, "UTF-8"); curl_easy_setopt(curl, CURLOPT_ENCODING, "UTF-8");
while (1) while (1)
{ {
//init_string(&sEgyLog); //init_string(&sEgyLog);
//init_string(&xEgyLog); //init_string(&xEgyLog);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &sEgyLog);
EgyLogKeszito(); EgyLogKeszito();
printf("Delaying %ds ... ", logdelay); printf("Delaying %ds ... ", logdelay);
sEgyLog.len = 0;//Klnben a kvetkez WebRequest ehhez (az elzhz) rn hozz az eredmnyt //sEgyLog.len = 0;//Klnben a kvetkez WebRequest ehhez (az elzhz) rn hozz az eredmnyt
free(sEgyLog.ptr); free(sEgyLog.ptr);
//xEgyLog.len = 0; //xEgyLog.len = 0;
//free(xEgyLog.ptr); //free(xEgyLog.ptr);
...@@ -827,7 +856,9 @@ int GetHossz(char *p, int h) ...@@ -827,7 +856,9 @@ int GetHossz(char *p, int h)
void OfflineMod() void OfflineMod()
{ {
FILE *f; FILE *f;
long fsize, fsizeelozo = 0; DIR *dir;
struct dirent *ent;
long fsize, fsizeelozo = 10;
char *fajltart = malloc(10); char *fajltart = malloc(10);
char *olvasandofile = malloc(10); char *olvasandofile = malloc(10);
...@@ -838,8 +869,6 @@ void OfflineMod() ...@@ -838,8 +869,6 @@ void OfflineMod()
//init_string(&sEgyLog); //init_string(&sEgyLog);
init_string(&xEgyLog); init_string(&xEgyLog);
DIR *dir;
struct dirent *ent;
if ((dir = opendir("offline")) != NULL) if ((dir = opendir("offline")) != NULL)
{ {
/* print all the files and directories within directory */ /* print all the files and directories within directory */
...@@ -850,16 +879,19 @@ void OfflineMod() ...@@ -850,16 +879,19 @@ void OfflineMod()
printf("FILE: '%s'\n", ent->d_name); printf("FILE: '%s'\n", ent->d_name);
olvasandofile = realloc(olvasandofile, 9 + ent->d_namlen); olvasandofile = realloc(olvasandofile, 9 + ent->d_namlen);
strcpy(olvasandofile, "offline\\"); strcpy_s(olvasandofile, 9, "offline\\");
strcat(olvasandofile, ent->d_name); strcat_s(olvasandofile, 9 + ent->d_namlen, ent->d_name);
f = fopen(olvasandofile, "rb"); fopen_s(&f,olvasandofile, "rb");
fseek(f, 0, SEEK_END); fseek(f, 0, SEEK_END);
fsize = ftell(f) + 1;//A fjl kdolstl fggen lehet, hogy egy karaktert kt byte reprezentl fsize = ftell(f) + 1;
fseek(f, 0, SEEK_SET); //same as rewind(f); fseek(f, 0, SEEK_SET); //same as rewind(f);
if (fsize > fsizeelozo) if (fsize > fsizeelozo)
{
fajltart = realloc(fajltart, fsize + 1); fajltart = realloc(fajltart, fsize + 1);
xEgyLog.ptr = realloc(xEgyLog.ptr, fsize * sizeof(char));//Ez biztosan nagyobb, vagy akkora, mint a dekdols utni karakterlnc
}
fsizeelozo = fsize; fsizeelozo = fsize;
delay(10); delay(10);
...@@ -872,9 +904,10 @@ void OfflineMod() ...@@ -872,9 +904,10 @@ void OfflineMod()
fajltart[fsize - 1] = 0; fajltart[fsize - 1] = 0;
xEgyLog.len = utf8_to_latin9(xEgyLog.ptr, fajltart, fsize); xEgyLog.len = utf8_to_latin9(xEgyLog.ptr, fajltart, fsize);
EnumString(xEgyLog, 0); EnumString(xEgyLog, 0);
printf("\n");
fsize = fsize;//DEBUG
//sEgyLog.len = 0;//Klnben a kvetkez WebRequest ehhez (az elzhz) rn hozz az eredmnyt //sEgyLog.len = 0;//Klnben a kvetkez WebRequest ehhez (az elzhz) rn hozz az eredmnyt
//free(sEgyLog.ptr); //free(sEgyLog.ptr);
...@@ -895,9 +928,9 @@ void OfflineMod() ...@@ -895,9 +928,9 @@ void OfflineMod()
else else
{ {
/* could not open directory */ /* could not open directory */
perror(""); //perror("");
printf("\nFile handling error...\n"); printf("\nFile handling error... Directory cannot be opened!\n");
return EXIT_FAILURE; return EXIT_FAILURE;
} }
......
...@@ -92,7 +92,7 @@ ...@@ -92,7 +92,7 @@
</PrecompiledHeader> </PrecompiledHeader>
<WarningLevel>Level3</WarningLevel> <WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization> <Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions);_CRT_SECURE_NO_WARNINGS</PreprocessorDefinitions> <PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions);</PreprocessorDefinitions>
<SDLCheck>true</SDLCheck> <SDLCheck>true</SDLCheck>
<AdditionalIncludeDirectories>$(ProjectDir)3rdparty\mysql-connector-c-6.1.11-win32\include;$(ProjectDir)3rdparty;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> <AdditionalIncludeDirectories>$(ProjectDir)3rdparty\mysql-connector-c-6.1.11-win32\include;$(ProjectDir)3rdparty;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile> </ClCompile>
...@@ -109,8 +109,9 @@ ...@@ -109,8 +109,9 @@
</PrecompiledHeader> </PrecompiledHeader>
<WarningLevel>Level3</WarningLevel> <WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization> <Optimization>Disabled</Optimization>
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions> <PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions);_CRT_SECURE_NO_WARNINGS</PreprocessorDefinitions>
<SDLCheck>true</SDLCheck> <SDLCheck>true</SDLCheck>
<AdditionalIncludeDirectories>$(ProjectDir)3rdparty;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile> </ClCompile>
<Link> <Link>
<SubSystem>Console</SubSystem> <SubSystem>Console</SubSystem>
...@@ -125,7 +126,7 @@ ...@@ -125,7 +126,7 @@
<Optimization>Disabled</Optimization> <Optimization>Disabled</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking> <FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions> <IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions);_CRT_SECURE_NO_WARNINGS</PreprocessorDefinitions> <PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions);</PreprocessorDefinitions>
<SDLCheck>true</SDLCheck> <SDLCheck>true</SDLCheck>
<AdditionalIncludeDirectories>$(ProjectDir)3rdparty\mysql-connector-c-6.1.11-win32\include;$(ProjectDir)3rdparty;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> <AdditionalIncludeDirectories>$(ProjectDir)3rdparty\mysql-connector-c-6.1.11-win32\include;$(ProjectDir)3rdparty;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile> </ClCompile>
...@@ -146,8 +147,9 @@ ...@@ -146,8 +147,9 @@
<Optimization>MaxSpeed</Optimization> <Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking> <FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions> <IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions> <PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions);_CRT_SECURE_NO_WARNINGS</PreprocessorDefinitions>
<SDLCheck>true</SDLCheck> <SDLCheck>true</SDLCheck>
<AdditionalIncludeDirectories>$(ProjectDir)3rdparty;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile> </ClCompile>
<Link> <Link>
<SubSystem>Console</SubSystem> <SubSystem>Console</SubSystem>
......
No preview for this file type
No preview for this file type
No preview for this file type
File suppressed by a .gitattributes entry, the file's encoding is unsupported, or the file size exceeds the limit.
File suppressed by a .gitattributes entry, the file's encoding is unsupported, or the file size exceeds the limit.
File suppressed by a .gitattributes entry, the file's encoding is unsupported, or the file size exceeds the limit.
File suppressed by a .gitattributes entry, the file's encoding is unsupported, or the file size exceeds the limit.
File suppressed by a .gitattributes entry, the file's encoding is unsupported, or the file size exceeds the limit.
#TargetFrameworkVersion=v4.0:PlatformToolSet=v140:EnableManagedIncrementalBuild=false:VCToolArchitecture=Native32Bit:WindowsTargetPlatformVersion=8.1
Debug|x64|D:\Users\gatsj\Documents\Visual Studio 2015\Projects\Prog1Hazi\|

\ No newline at end of file

\ No newline at end of file

\ No newline at end of file

\ No newline at end of file

\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment