Repository: microsoft/garnet
File: libs/server/Objects/List/ListObjectImpl.cs (C#)

Code before:
                    return;
                }

                byte* ptr = input + sizeof(ObjectInputHeader);
                byte* startptr = ptr;
                byte* end = input + length;

                byte* indexParam = default;
                var indexParamSize = 0;

                // index
                if (!RespReadUtils.ReadPtrWithLengthHeader(ref indexParam, ref indexParamSize, ref startptr, end))
                    return;

                if (NumUtils.TryBytesToInt(indexParam, indexParamSize, out var index) == false)
                {
                    while (!RespWriteUtils.WriteError(CmdStrings.RESP_ERR_GENERIC_VALUE_IS_NOT_INTEGER.ToArray(), ref _o_curr, _o_end))
                        ObjectUtils.ReallocateOutput(ref output, ref isMemory, ref _out_ptr, ref ptrHandle, ref _o_curr, ref _o_end);
                    return;
                }

                index = index < 0 ? list.Count + index : index;

                if (index > list.Count - 1)
                {
                    while (!RespWriteUtils.WriteError(CmdStrings.RESP_ERR_GENERIC_OFFSETOUTOFRANGE.ToArray(), ref _o_curr, _o_end))
                        ObjectUtils.ReallocateOutput(ref output, ref isMemory, ref _out_ptr, ref ptrHandle, ref _o_curr, ref _o_end);
                    return;
                }

                // element
                if (!RespReadUtils.ReadByteArrayWithLengthHeader(out var element, ref startptr, end))
                    return;

                if (index == 0)
                {
                    UpdateSize(list.First.Value, false);
                    list.First.Value = element;
                    UpdateSize(list.First.Value, true);
                }
                else if (index == list.Count - 1)
                {
                    UpdateSize(list.Last.Value, false);
                    list.Last.Value = element;
                    UpdateSize(list.Last.Value, true);
                }
                else
                {
                    var start = 0;
                    foreach (var node in list.Nodes())
                    {

Review comment (suggestion):
```suggestion
                    while (!RespWriteUtils.WriteError(CmdStrings.RESP_ERR_GENERIC_OFFSETOUTOFRANGE, ref _o_curr, _o_end))
```

Code after:
                    return;
                }

                byte* input_startptr = input + sizeof(ObjectInputHeader);
                byte* input_currptr = input_startptr;
                byte* input_end = input + length;

                byte* indexParam = default;
                var indexParamSize = 0;

                // index
                if (!RespReadUtils.ReadPtrWithLengthHeader(ref indexParam, ref indexParamSize, ref input_currptr, input_end))
                    return;

                if (NumUtils.TryBytesToInt(indexParam, indexParamSize, out var index) == false)
                {
                    while (!RespWriteUtils.WriteError(CmdStrings.RESP_ERR_GENERIC_VALUE_IS_NOT_INTEGER, ref output_currptr, output_end))
                        ObjectUtils.ReallocateOutput(ref output, ref isMemory, ref output_startptr, ref ptrHandle, ref output_currptr, ref output_end);
                    return;
                }

                index = index < 0 ? list.Count + index : index;

                if (index > list.Count - 1 || index < 0)
                {
                    while (!RespWriteUtils.WriteError(CmdStrings.RESP_ERR_GENERIC_INDEX_OUT_RANGE, ref output_currptr, output_end))
                        ObjectUtils.ReallocateOutput(ref output, ref isMemory, ref output_startptr, ref ptrHandle, ref output_currptr, ref output_end);
                    return;
                }

                // element
                if (!RespReadUtils.ReadByteArrayWithLengthHeader(out var element, ref input_currptr, input_end))
                    return;

                var targetNode = index == 0 ? list.First
                    : (index == list.Count - 1 ? list.Last
                        : list.Nodes().ElementAtOrDefault(index));

                UpdateSize(targetNode.Value, false);
                targetNode.Value = element;
                UpdateSize(targetNode.Value);

                while (!RespWriteUtils.WriteDirect(CmdStrings.RESP_OK, ref output_currptr, output_end))
                    ObjectUtils.ReallocateOutput(ref output, ref isMemory, ref output_startptr, ref ptrHandle, ref output_currptr, ref output_end);

                // Write bytes parsed from input and count done, into output footer
                _output.bytesDone = (int)(input_currptr - input_startptr);
                _output.countDone = 1;
                _output.opsDone = 1;
            }
            finally