Skip to content

Commit 6cf2b1f

Browse files
Fix for Array index out of bounds
Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
1 parent 1a3aa67 commit 6cf2b1f

1 file changed

Lines changed: 45 additions & 34 deletions

File tree

java_package/brainflow/src/main/java/brainflow/examples/EEGMetrics.java

Lines changed: 45 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -49,41 +49,52 @@ private static int parse_args (String[] args, BrainFlowInputParams params)
4949
int board_id = -1;
5050
for (int i = 0; i < args.length; i++)
5151
{
52-
if (args[i].equals ("--ip-address"))
52+
String arg = args[i];
53+
if (arg.equals ("--ip-address") || arg.equals ("--serial-port") || arg.equals ("--ip-port")
54+
|| arg.equals ("--ip-protocol") || arg.equals ("--other-info") || arg.equals ("--board-id")
55+
|| arg.equals ("--timeout") || arg.equals ("--serial-number") || arg.equals ("--file"))
5356
{
54-
params.ip_address = args[i + 1];
55-
}
56-
if (args[i].equals ("--serial-port"))
57-
{
58-
params.serial_port = args[i + 1];
59-
}
60-
if (args[i].equals ("--ip-port"))
61-
{
62-
params.ip_port = Integer.parseInt (args[i + 1]);
63-
}
64-
if (args[i].equals ("--ip-protocol"))
65-
{
66-
params.ip_protocol = Integer.parseInt (args[i + 1]);
67-
}
68-
if (args[i].equals ("--other-info"))
69-
{
70-
params.other_info = args[i + 1];
71-
}
72-
if (args[i].equals ("--board-id"))
73-
{
74-
board_id = Integer.parseInt (args[i + 1]);
75-
}
76-
if (args[i].equals ("--timeout"))
77-
{
78-
params.timeout = Integer.parseInt (args[i + 1]);
79-
}
80-
if (args[i].equals ("--serial-number"))
81-
{
82-
params.serial_number = args[i + 1];
83-
}
84-
if (args[i].equals ("--file"))
85-
{
86-
params.file = args[i + 1];
57+
if (i + 1 >= args.length)
58+
{
59+
throw new IllegalArgumentException ("Missing value for argument: " + arg);
60+
}
61+
String value = args[++i];
62+
if (arg.equals ("--ip-address"))
63+
{
64+
params.ip_address = value;
65+
}
66+
else if (arg.equals ("--serial-port"))
67+
{
68+
params.serial_port = value;
69+
}
70+
else if (arg.equals ("--ip-port"))
71+
{
72+
params.ip_port = Integer.parseInt (value);
73+
}
74+
else if (arg.equals ("--ip-protocol"))
75+
{
76+
params.ip_protocol = Integer.parseInt (value);
77+
}
78+
else if (arg.equals ("--other-info"))
79+
{
80+
params.other_info = value;
81+
}
82+
else if (arg.equals ("--board-id"))
83+
{
84+
board_id = Integer.parseInt (value);
85+
}
86+
else if (arg.equals ("--timeout"))
87+
{
88+
params.timeout = Integer.parseInt (value);
89+
}
90+
else if (arg.equals ("--serial-number"))
91+
{
92+
params.serial_number = value;
93+
}
94+
else if (arg.equals ("--file"))
95+
{
96+
params.file = value;
97+
}
8798
}
8899
}
89100
return board_id;

0 commit comments

Comments
 (0)