Jump to content

Array issues and bugs


Dale0
 Share

Recommended Posts

Hi,

I'm trying to write a script to check user access on the network when I've run into issues using arrays.

The below script, with sample data from our network, raises 2 issues for me.

1) _ArrayUnique() doesn't always work.  When I tested it with basic text strings, it was ok.  But with this test data which I generated from our server using an Active Directoy query, _ArrayUnique() fails as demonstrated by the second output.

2) I thought maybe the issue could be something to do with the parameters I used, so I tested _ArrayUnique() with the deault parameters.  Somehow _ArrayUnique() has added an additional element to the array as demonstrated by the third output.  $iFlags wasn't set and it should default to 0, which means no array count stored in element [0].

PS: I forget to mention that I'm using AutoIT v3.3.10.2

#include <AD.au3>
#include <Array.au3>

Local $data[25]
Local $result

Dim $data[14]
$data[0] = 13
$data[1] = "CN=Admin Team,OU=Security Groups,OU=Company,DC=test,DC=local"
$data[2] = "CN=Administrators,CN=Builtin,DC=test,DC=local|CN=Domain Admins,CN=Users,DC=test,DC=local"
$data[3] = "CN=Domain Admins,CN=Users,DC=test,DC=local"
$data[4] = "CN=Domain Users,CN=Users,DC=test,DC=local|CN=Service Team,OU=Security Groups,OU=Company,DC=test,DC=local"
$data[5] = "CN=NRMA Team,OU=Security Groups,OU=Company,DC=test,DC=local"
$data[6] = "CN=RDR Edit,OU=Control Groups,OU=Company,DC=test,DC=local"
$data[7] = "CN=RDR Report,OU=Control Groups,OU=Company,DC=test,DC=local"
$data[8] = "CN=Restricted Admin,OU=Security Groups,OU=Company,DC=test,DC=local"
$data[9] = "CN=Service Team,OU=Security Groups,OU=Company,DC=test,DC=local"
$data[10] = "CN=Users,CN=Builtin,DC=test,DC=local|CN=Domain Users,CN=Users,DC=test,DC=local|CN=Admin Team,OU=Security Groups,OU=Company,DC=test,DC=local"
$data[11] = "CN=Vehicle Quote Edit,OU=Control Groups,OU=Company,DC=test,DC=local|CN=Admin Team,OU=Security Groups,OU=Company,DC=test,DC=local"
$data[12] = "CN=Domain Users,CN=Users,DC=test,DC=local|CN=Admin Team,OU=Security Groups,OU=Company,DC=test,DC=local"
$data[13] = "CN=Users,CN=Builtin,DC=test,DC=local|CN=Domain Users,CN=Users,DC=test,DC=local|CN=Service Team,OU=Security Groups,OU=Company,DC=test,DC=local"

_ArrayDisplay($data, "Before sort")

$result = $data
_ArraySort($result, 0, 1)
$result = _ArrayUnique($result, 1, 1)
_ArrayDisplay($result, "After _ArrayUnique() ignoring element 0")

;_ArraySort($data)
$result = _ArrayUnique($data)
_ArrayDisplay($result, "2 Bugs - After _ArrayUnique() including element 0")
Edited by Dale0
Link to comment
Share on other sites

....

  $iFlags wasn't set and it should default to 0, which means no array count stored in element [0].

....

 

From help file:-

Remarks
Returns an array containing the unique strings. If the parameter $iFlags is set to 1, the first element $aArrayRet[0] contains the number of strings returned.

The second _ArrayDisplay should be displaying the result from:-

$result = _ArrayUnique($result, 1, 1, 0, 0)

Note:  The 5th parameter, $iFlags, is "0".  The first element $aArrayRet[0] will not contain the number of strings returned.

Edit: The default parameters are _ArrayUnique($aArray, 1, 0, 0, 1)

May I suggest for future good coding practise. When multiple parameters require either a "1" or a "0", then all the default values should be all "1"'s or all "0"'s.  And not a mixture of both 1's and 0's as _ArrayUnique is. So if you know one default value, you will know all the default values.

Edited by Malkey
Link to comment
Share on other sites

The documentation for this function needs to be updated to reflect the true default value for $iFlags.  I personally took the Default value to use some logic as follows:

One would imagine $iFlags should be smart enough, when set to Default, that if the supplied array is 0 based, then the return array is zero based (and likewise for 1 based arrays too).  So then $iFlags should not be defaulted to 0 or 1 (as you suggest), but should be as per the current documentation with an explaination.

Who knows how it was meant to be, but this could be inter-twined with the first bug I meantioned.

Can someone please indicate if others can reproduce the first bug, and if so, when a potential patch be released (or at least a work-around)?

Link to comment
Share on other sites

One would imagine $iFlags should be smart enough, when set to Default, that if the supplied array is 0 based, then the return array is zero based (and likewise for 1 based arrays too).

 

And how exactly would you smartly decide whether the array holds a count at [0] or not?

BTW, AutoIt arrays are always 0-based.

Edited by jchd

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

  • Moderators

Malkey,

 

May I suggest for future good coding practise. When multiple parameters require either a "1" or a "0", then all the default values should be all "1"'s or all "0"'s

That is not always logical internally. But the new Array UDF (which will be in the next Beta release) allows the use of "Default" in place of any optional parameter which solves the problem another way. This is something we are trying to introduce throughout the UDFs, but obviously it is not a short job. ;)

Dale0,

Welcome to the AutoIt forum. :)

 

One would imagine $iFlags should be smart enough...

Well, it is not - and I see no reason to see why it should link the original array with the return array. Indeed I can think of several good reasons why the 2 arrays might want different [0] element behaviour. :)

As to your "first bug" - what is wrong with the return? I see 13 different lines in the array you provide and 13 different elements in the return from _ArrayUnique. Perhaps the proportional font confused you - in the sorted array elements 4/5 and 11/12 are not identical, even though the line length appears the same: ;)

[4]|CN=Domain Users,CN=Users,DC=test,DC=local|CN=Admin Team,OU=Security Groups,OU=Company,DC=test,DC=local
[5]|CN=Domain Users,CN=Users,DC=test,DC=local|CN=Service Team,OU=Security Groups,OU=Company,DC=test,DC=local

[11]|CN=Users,CN=Builtin,DC=test,DC=local|CN=Domain Users,CN=Users,DC=test,DC=local|CN=Admin Team,OU=Security Groups,OU=Company,DC=test,DC=local
[12]|CN=Users,CN=Builtin,DC=test,DC=local|CN=Domain Users,CN=Users,DC=test,DC=local|CN=Service Team,OU=Security Groups,OU=Company,DC=test,DC=local
Easy to spot the difference in a mono-spaced font. ;)

So in short, no bug and the function behaves as it is documented. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...