Wrong implementation of array.CopyTo in jsDateConstructor?

Feb 22, 2012 at 11:36 PM
Edited Feb 22, 2012 at 11:38 PM


First of all great project!! It really works really well for what I am in need of.

I am using version 0.9.2 and today I found what seems to be a bug on the code in several of the SetXXX functions of the jsDateConstructor.cs file.

On this functions the basic idea as I would guess it is that you use the first parameter and then pass the rest to the more specific functions, let's say I want to set hour, minute and second, the SetHour function is called first, uses the parameter [0] and then passes the rest to the SetMinute function that uses the parameter[0] and so forth.

this is implemented like this:


            if (parameters.Length > 1) {
                JsInstance[] innerParams = new JsInstance[parameters.Length - 1];
                parameters.CopyTo(innerParams, 1);
                target = (JsDate)SetSecondsImpl(target, innerParams);


Here parameters is the original array and innerParms is the array we want to send to the next function.

The problem is at parameters.CopyTo(...) , this call actually tries to copy the entire parameters into innerParams starting at position 1 (of the innerParams array), this is a problem because we just created this array with 1 less item that the original parameters array.  You can see the full description of this function here: http://msdn.microsoft.com/en-us/library/06x742cw.aspx

What I think is correct is to replace the previous line with the Array.Copy function like this:

Array.Copy(parameters, 1, innerParams, 0, parameters.Length - 1);

this will copy all elements from parameters starting at position 1 into innerParams starting at position 0. Here you can see an explanation of the Array.Copy function: http://msdn.microsoft.com/en-us/library/z50k9bft.aspx


Please ignore this if I'm totally off the mark here.

Keep up the good work!



Sebastian Andres

Mar 13, 2012 at 6:11 PM

Thank you for your sugesstion, I've fixed it.