Modify

Opened 10 years ago

Closed 10 years ago

Last modified 10 years ago

#755 closed Bug (Fixed)

_FileReadToArray broken in 3.3.0.0

Reported by: Melba23 Owned by: Jpm
Milestone: 3.3.1.0 Component: AutoIt
Version: 3.3.0.0 Severity: None
Keywords: filereadtoarray Cc:

Description

If an array containing empty elements is saved by _FileWriteFromArray, it can no longer be read by _FileReadToArray, which returns error 2 "cannot split file".

I track whether certain files listed in an array have already been accessed by creating a shadow array of the same size and setting its elements to 1 when the corresponding file in the first array is accessed. The shadow array is then saved on exit using _FileWriteFromArray. On startup I load the shadow file and compare its size to the array created from the files on disk as a form of checksum. Under 3.3.0.0 the shadow array, which contains a great number of empty elements (ie long strings of 0x0D0A interspersed with the odd 1), will not load as an array. I have substituted the "old" _FileReadToArray UDF from 3.2.12.1 and the file loads to an array without problem.

Creating the array and then setting all elements to 0 in a loop does enable the "new" _FileReadToArray UDF from 3.3.0.0 to read the array, so the problem does appear to be with the empty elements.

Attachments (0)

Change History (5)

comment:1 Changed 10 years ago by Jpm

please post a repro scriptas stated in trak report submission.
I test with the following without any problem under 3.3.0.0

#include <file.au3>
#include <array.au3>

$file="#755.txt"

Dim $aRecords
If Not _FileReadToArray($file,$aRecords) Then
   MsgBox(4096,"Error", " Error reading log to Array     error:" & @error)
   Exit
EndIf

$out="temp.txt"
If Not _FileWriteFromArray($out,$aRecords,1) Then
   MsgBox(4096,"Error", " Error writing log to Array     error:" & @error)
   Exit
EndIf

If Not _FileReadToArray($out,$aRecords) Then
   MsgBox(4096,"Error", " Error rereading log to Array     error:" & @error)
   Exit
EndIf

_ArrayDisplay($aRecords,$out)

with #755.txt

line1

line3

comment:2 Changed 10 years ago by Melba23

My apologies for not posting a script. First time I have had to use this.

#include <File.au3>
#include <Array.au3>

Global $aArray[25], $aArray2

_FileWriteFromArray(@ScriptDir & "\test.arr", $aArray)

_FileReadToArray(@ScriptDir & "\test.arr", $aArray2)

ConsoleWrite("Empty Array: " & @error & @CRLF)

If IsArray($aArray2) Then 
	_ArrayDisplay($aArray2)
Else
	MsgBox(0, "Error", "Array2 is not an array")
EndIf

$aArray[0] = 1

_FileWriteFromArray(@ScriptDir & "\test.arr", $aArray)

_FileReadToArray(@ScriptDir & "\test.arr", $aArray2)

ConsoleWrite("Part-filled Array: " & @error & @CRLF)

If IsArray($aArray2) Then 
	_ArrayDisplay($aArray2)
Else
	MsgBox(0, "Error", "Array2 is not an array")
EndIf

For $i = 0 To 24
	$aArray[$i] = 0
Next

_FileWriteFromArray(@ScriptDir & "\test.arr", $aArray)

_FileReadToArray(@ScriptDir & "\test.arr", $aArray2)

ConsoleWrite("Filled Array: " & @error & @CRLF)

If IsArray($aArray2) Then 
	_ArrayDisplay($aArray2)
Else
	MsgBox(0, "Error", "Array2 is not an array")
EndIf

Exit

On my machine this gives "no array" when reloading the empty array, a 1 element array when the first element is filled, and a 25 element array when all are filled.

The same script on 3.2.12.1 gives 25 element arrays in all cases, with the correct elements filled when set.

Hope that makes it clear. Only difference is that 3.3.0.0 is running on Vista, and 3.12.1.0 is on Win98 - although as the Vista machine did not error when it was using 3.2.12.1 and gave an error on first run with 3.3.0.0 I do not believe the OS to be a factor.

M23

comment:3 Changed 10 years ago by Melba23

Good morning,

Investigating further, the new _FileReadToArray appears to ignore empty elements after the final filled element as the following code should show:

#include <File.au3>

For $i = 0 To 24

	Global $aArray1[25], $aArray2
	
	$aArray1[$i] = 1

	_FileWriteFromArray(@ScriptDir & "\test.arr", $aArray1)

	_FileReadToArray(@ScriptDir & "\test.arr", $aArray2)

	If IsArray($aArray2) Then 
		ConsoleWrite("Array1 size: " & UBound($aArray1) & _
" - Array2 size (less [0] sizing element): " & UBound($aArray2) -1 & @CRLF)
	Else
		MsgBox(0, "Error", "Array2 is not an array")
	EndIf

Next

Exit

My results always have the second array truncated after the filled element as the empty elements beyond are ignored. I have run it up to 2000 elements and the result is always the same. Adding a second element to the array just moves the truncation point to that value.

Hope this helps to solve the problem.

M23

comment:4 Changed 10 years ago by Jpm

  • Milestone set to 3.3.1.0
  • Owner set to Jpm
  • Resolution set to Fixed
  • Status changed from new to closed

Fixed in version: 3.3.1.0

comment:5 Changed 10 years ago by Melba23

Thanks

M23

Guidelines for posting comments:

  • You cannot re-open a ticket but you may still leave a comment if you have additional information to add.
  • In-depth discussions should take place on the forum.

For more information see the full version of the ticket guidelines here.

Add Comment

Modify Ticket

Action
as closed The owner will remain Jpm.
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.