-
Notifications
You must be signed in to change notification settings - Fork 2
Add files via upload #13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,14 @@ | ||||||||||||||
| public class BadArray { | ||||||||||||||
| private static int[] store = new int[4]; | ||||||||||||||
|
|
||||||||||||||
| public static void putData(int pos, int num) { | ||||||||||||||
| if (pos < 0) { | ||||||||||||||
| return; | ||||||||||||||
| } | ||||||||||||||
| store[pos] = num; | ||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔴 AI 代码审查发现问题 📋 问题概述
📍 问题详情🔴 问题 1 | 严重程度:
|
||||||||||||||
| } | ||||||||||||||
|
Comment on lines
+4
to
+9
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 缺少上界检查,会抛出
🛡️ 建议的修复 public static void putData(int pos, int num) {
- if (pos < 0) {
+ if (pos < 0 || pos >= store.length) {
return;
}
store[pos] = num;
}如果更倾向于显式失败而非静默忽略,可改为: public static void putData(int pos, int num) {
- if (pos < 0) {
- return;
- }
- store[pos] = num;
+ if (pos < 0 || pos >= store.length) {
+ throw new IndexOutOfBoundsException("pos out of range: " + pos);
+ }
+ store[pos] = num;
}🤖 Prompt for AI Agents |
||||||||||||||
|
|
||||||||||||||
| public static void main(String[] args) { | ||||||||||||||
| putData(5, 100); | ||||||||||||||
| } | ||||||||||||||
|
Comment on lines
+11
to
+13
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
🛠️ 建议的修复 public static void main(String[] args) {
- putData(5, 100);
+ putData(3, 100);
}📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||
| } | ||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔴 AI 代码审查发现问题
📋 问题概述
📍 问题详情
🔴 问题 1 | 严重程度:
HIGH| 行号:8💬 详细说明:
📝 问题代码:
💡 修复建议:
✅ 修复示例:
🔗 参考链接
无