Skip to content

Fix for Array index out of bounds#806

Merged
Andrey1994 merged 1 commit intomasterfrom
finding-autofix-3e424911
Apr 26, 2026
Merged

Fix for Array index out of bounds#806
Andrey1994 merged 1 commit intomasterfrom
finding-autofix-3e424911

Conversation

@Andrey1994
Copy link
Copy Markdown
Member

To fix this safely without changing intended behavior, validate that each option requiring a value actually has a following argument before accessing args[i + 1]. The best minimal fix is:

  1. Detect recognized options.
  2. Check i + 1 >= args.length; if true, throw a clear IllegalArgumentException.
  3. Use the validated next argument once (String value = args[++i];) and assign/parse it per option.

This avoids out-of-bounds access, improves error messages, and keeps existing parsing semantics.
All changes are in java_package/brainflow/src/main/java/brainflow/examples/EEGMetrics.java, inside parse_args.

Suggested fixes powered by Copilot Autofix. Review carefully before merging.

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
@Andrey1994 Andrey1994 marked this pull request as ready for review April 26, 2026 15:33
@Andrey1994 Andrey1994 merged commit 146c52d into master Apr 26, 2026
38 checks passed
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 6cf2b1f07b

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

{
throw new IllegalArgumentException ("Missing value for argument: " + arg);
}
String value = args[++i];
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Reject missing option values before consuming next flag

Using String value = args[++i]; without checking whether args[i + 1] is itself another CLI flag causes a new parsing regression: if a value is omitted in the middle (for example --ip-address --serial-port COM3), --serial-port is consumed as the IP value and then skipped entirely, so serial_port is never parsed. This commit adds missing-value validation, so this case should also raise an IllegalArgumentException instead of silently swallowing the next option.

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant