Repository: neovim/neovim
File: src/nvim/api/command.c (C)

Code before:
#include "nvim/globals.h"
#include "nvim/lua/executor.h"
#include "nvim/macros_defs.h"
#include "nvim/mbyte.h"
#include "nvim/memory.h"
#include "nvim/memory_defs.h"
#include "nvim/ops.h"
#include "nvim/pos_defs.h"
#include "nvim/regexp.h"
#include "nvim/strings.h"
#include "nvim/types_defs.h"
#include "nvim/usercmd.h"
#include "nvim/vim_defs.h"
#include "nvim/window.h"

#ifdef INCLUDE_GENERATED_DECLARATIONS
# include "api/command.c.generated.h"
#endif

/// Parse arguments for mapping commands, preserving whitespace in RHS
/// @param arg_str  The argument string to parse
/// @param arena    Arena allocator
/// @return Array with at most 2 elements: [lhs, rhs]
static Array parse_mapping_args(const char *arg_str, Arena *arena)
{
  Array args = arena_array(arena, 2);  // Allocate for at most 2 arguments

  char *lhs_start = (char *)arg_str;
  char *lhs_end = skiptowhite(lhs_start);
  size_t lhs_len = (size_t)(lhs_end - lhs_start);

  // Add the LHS (first argument)
  ADD_C(args, STRING_OBJ(cstrn_as_string(lhs_start, lhs_len)));

  // Add the RHS (second argument) if it exists, preserving all whitespace
  char *rhs_start = skipwhite(lhs_end);
  if (*rhs_start != NUL) {
    size_t rhs_len = strlen(rhs_start);
    ADD_C(args, STRING_OBJ(cstrn_as_string(rhs_start, rhs_len)));
  }

  return args;
}

/// Parse command line.
///
/// Doesn't check the validity of command arguments.
///
/// @param str       Command line string to parse. Cannot contain "\n".
/// @param opts      Optional parameters. Reserved for future use.
/// @param[out] err  Error details, if any.

Review comment (suggestion):
does MAXSIZE_TEMP_ARRAY work here ? 

```suggestion
  MAXSIZE_TEMP_ARRAY(args, 2);
```

Code after:
#include "nvim/globals.h"
#include "nvim/lua/executor.h"
#include "nvim/macros_defs.h"
#include "nvim/mbyte.h"
#include "nvim/memory.h"
#include "nvim/memory_defs.h"
#include "nvim/ops.h"
#include "nvim/pos_defs.h"
#include "nvim/regexp.h"
#include "nvim/strings.h"
#include "nvim/types_defs.h"
#include "nvim/usercmd.h"
#include "nvim/vim_defs.h"
#include "nvim/window.h"

#ifdef INCLUDE_GENERATED_DECLARATIONS
# include "api/command.c.generated.h"
#endif

/// Parse arguments for :map/:abbrev commands, preserving whitespace in RHS.
/// @param arg_str  The argument string to parse
/// @param arena    Arena allocator
/// @return Array with at most 2 elements: [lhs, rhs]
static Array parse_map_cmd(const char *arg_str, Arena *arena)
{
  Array args = arena_array(arena, 2);

  char *lhs_start = (char *)arg_str;
  char *lhs_end = skiptowhite(lhs_start);
  size_t lhs_len = (size_t)(lhs_end - lhs_start);

  // Add the LHS (first argument)
  ADD_C(args, STRING_OBJ(cstrn_as_string(lhs_start, lhs_len)));

  // Add the RHS (second argument) if it exists, preserving all whitespace
  char *rhs_start = skipwhite(lhs_end);
  if (*rhs_start != NUL) {
    size_t rhs_len = strlen(rhs_start);
    ADD_C(args, STRING_OBJ(cstrn_as_string(rhs_start, rhs_len)));
  }

  return args;
}

/// Parse command line.
///
/// Doesn't check the validity of command arguments.
///
/// @param str       Command line string to parse. Cannot contain "\n".
/// @param opts      Optional parameters. Reserved for future use.
/// @param[out] err  Error details, if any.