04-16-2014 08:14 AM
Hi,
please look at this code:
void speichere_messoptionen(int i, int iAction) { int Opt_Datei; Opt_Datei = OpenFile ("nmv_opt.opt", VAL_WRITE_ONLY, iAction, VAL_ASCII); FmtFile(Opt_Datei,"***%s %i. Aufruf ***", "speichere_messoptionen",i); /*Einlesen der Optionen zum Messen*/ WriteFile (Opt_Datei, "\n",1); FmtFile(Opt_Datei,"%i[b2]", 2); WriteFile (Opt_Datei, "\n",1); FmtFile(Opt_Datei,"%f", 3.0); WriteFile (Opt_Datei, "\n",1); FmtFile(Opt_Datei,"%i[b2]", 4); WriteFile (Opt_Datei, "\n",1); FmtFile(Opt_Datei,"%i[b2]", 5); WriteFile (Opt_Datei, "\n",1); FmtFile(Opt_Datei,"%i[b2]", 6); WriteFile (Opt_Datei, "\n",1); FmtFile(Opt_Datei,"%i[b2]", 7); WriteFile (Opt_Datei, "\n",1); FmtFile(Opt_Datei,"%i[b2]", 8); WriteFile (Opt_Datei, "\n",1); CloseFile (Opt_Datei); } void lese_messoptionen(void) { int Opt_Datei; int ret = 0; Opt_Datei = OpenFile ("nmv_opt.opt", VAL_READ_ONLY, VAL_TRUNCATE, VAL_ASCII); //bug ret = ReadFile (Opt_Datei, "\n", 1); // lese ein Zeichen ohne buffer CloseFile (Opt_Datei); } int main (int argc, char *argv[]) { int i = 0; if (InitCVIRTE (0, argv, 0) == 0) return -1; /* out of memory */ //erster Aufruf der Funktion mit Aktion TRUNCATE speichere_messoptionen(1, VAL_TRUNCATE); //hier bug verursachen lese_messoptionen(); //zweiter Aufruf der Funktion allerding mit Append (Aktion ist eigentlich egal, dann habe ich den Fehler aber in einer Datei ;-) speichere_messoptionen(2, VAL_APPEND); return 0; }
ouput with CVI 2013 SP1 is:
***speichere_messoptionen 1. Aufruf *** 2 3.0 4 5 6 7 8 ***speichere_messoptionen 2. Aufruf ****2*3.0*4*5*6*7*8*
output with CVI 2009 is:
***speichere_messoptionen 1. Aufruf *** 2 3.0 4 5 6 7 8 ***speichere_messoptionen 2. Aufruf *** 2 3.0 4 5 6 7 8
The error happens in lese_messoptionen ReadFile(Opt_Datei, "\n",1); It's wrong to use "\n". Old software, sleeping bug
Is it a CLANG feature or a CLANG bug?
Regards,
Thomas
04-17-2014 06:11 AM
Hi Thomas,
seems that this is a bug. I will report it, thank you for your code!
Best regards
Matijas Milos
04-22-2014 01:01 AM
Hi Thomas,
could you please describe what you are trying to achieve or what do you need it for ? It would be really helpful.
Regards
Matijas
04-22-2014 01:17 AM
Hi Matijas,
i have to change some old software written with CVI 2009 or older by an other coder. Today i'm using CVI 2013. After compiling the code with CLANG i notice this "bug". This bug is based on a "sleeping" bug inside our code. The code read some configuration options from a file. I guess, the coder want to read the new line character "\n" to set the filepointer into the next line, but i am not shure. Now i will rewrite this code in a better way.
Hope this helps,
Regards,
Thomas
04-23-2014 01:11 AM
Hi Thomas,
that is what I get as an answer to my report
"It may be a bug in CVI 2009, but I do not think the code they have should work the way they want it to. The read function will start reading at the current position of the file pointer. If the coder wants to move the file location to the next line by reading a single byte that is ok. However, it does not make any sense to specify a literal string in the buffer parameter. The parameter is designed to take a character array variable to hold the contents of the file."
I hope this will explain you the things.
Best regards
Matijas