質問編集履歴

7

errorの出る場所をコード内に明記した。

2021/09/23 09:57

投稿

alizona
alizona

スコア126

test CHANGED
File without changes
test CHANGED
@@ -108,6 +108,8 @@
108
108
 
109
109
 
110
110
 
111
+  //ここでえらーが出ます。このコードは input[1,1] や、input[1]に対応するためのコードです。
112
+
111
113
  if(nums[0]==nums[numsSize-1]){
112
114
 
113
115
  num++;

6

error の追加

2021/09/23 09:57

投稿

alizona
alizona

スコア126

test CHANGED
File without changes
test CHANGED
@@ -174,6 +174,86 @@
174
174
 
175
175
  ```error
176
176
 
177
-
177
+ =================================================================
178
+
179
+ ==30==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x6020000001b0 at pc 0x55a3fe08f25d bp 0x7fff6f41e710 sp 0x7fff6f41e700
180
+
181
+ READ of size 4 at 0x6020000001b0 thread T0
182
+
183
+ #2 0x7f29855c20b2 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x270b2)
184
+
185
+ 0x6020000001b1 is located 0 bytes to the right of 1-byte region [0x6020000001b0,0x6020000001b1)
186
+
187
+ allocated by thread T0 here:
188
+
189
+ #0 0x7f2986207bc8 in malloc (/lib/x86_64-linux-gnu/libasan.so.5+0x10dbc8)
190
+
191
+ #3 0x7f29855c20b2 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x270b2)
192
+
193
+ Shadow bytes around the buggy address:
194
+
195
+ 0x0c047fff7fe0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
196
+
197
+ 0x0c047fff7ff0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
198
+
199
+ 0x0c047fff8000: fa fa 00 04 fa fa fd fa fa fa fd fa fa fa fd fa
200
+
201
+ 0x0c047fff8010: fa fa 00 fa fa fa fd fa fa fa fd fa fa fa fd fa
202
+
203
+ 0x0c047fff8020: fa fa fd fa fa fa fd fa fa fa fd fa fa fa 00 00
204
+
205
+ =>0x0c047fff8030: fa fa fd fa fa fa[01]fa fa fa fa fa fa fa fa fa
206
+
207
+ 0x0c047fff8040: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
208
+
209
+ 0x0c047fff8050: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
210
+
211
+ 0x0c047fff8060: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
212
+
213
+ 0x0c047fff8070: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
214
+
215
+ 0x0c047fff8080: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
216
+
217
+ Shadow byte legend (one shadow byte represents 8 application bytes):
218
+
219
+ Addressable: 00
220
+
221
+ Partially addressable: 01 02 03 04 05 06 07
222
+
223
+ Heap left redzone: fa
224
+
225
+ Freed heap region: fd
226
+
227
+ Stack left redzone: f1
228
+
229
+ Stack mid redzone: f2
230
+
231
+ Stack right redzone: f3
232
+
233
+ Stack after return: f5
234
+
235
+ Stack use after scope: f8
236
+
237
+ Global redzone: f9
238
+
239
+ Global init order: f6
240
+
241
+ Poisoned by user: f7
242
+
243
+ Container overflow: fc
244
+
245
+ Array cookie: ac
246
+
247
+ Intra object redzone: bb
248
+
249
+ ASan internal: fe
250
+
251
+ Left alloca redzone: ca
252
+
253
+ Right alloca redzone: cb
254
+
255
+ Shadow gap: cc
256
+
257
+ ==30==ABORTING
178
258
 
179
259
  ```

5

コードの修正

2021/09/23 09:51

投稿

alizona
alizona

スコア126

test CHANGED
File without changes
test CHANGED
@@ -26,7 +26,7 @@
26
26
 
27
27
 
28
28
 
29
-
29
+ //修正前
30
30
 
31
31
  ```C
32
32
 
@@ -92,6 +92,8 @@
92
92
 
93
93
 
94
94
 
95
+ //修正後
96
+
95
97
  ```C
96
98
 
97
99
 
@@ -102,29 +104,69 @@
102
104
 
103
105
  int i;
104
106
 
105
- int num=1;
107
+ int num=0;
106
-
107
-
108
108
 
109
109
 
110
+
111
+ if(nums[0]==nums[numsSize-1]){
112
+
113
+ num++;
114
+
115
+ }
116
+
117
+
110
118
 
111
119
  for (i = 1;i < numsSize;i++) {
112
120
 
113
121
 
114
122
 
123
+
124
+
115
125
  if(nums[i-1]!=nums[i]){
116
126
 
117
- nums[num]=nums[i];
127
+
118
128
 
129
+
130
+
131
+ if(i==numsSize-1){
132
+
133
+ nums[num]=nums[i-1];
134
+
119
- num++;
135
+ num++;
136
+
137
+
138
+
139
+ nums[num]=nums[i];
140
+
141
+ num++;
142
+
143
+
144
+
145
+ }else{
146
+
147
+ nums[num]=nums[i-1];
148
+
149
+ num++;
150
+
151
+ }
120
152
 
121
153
  }
122
154
 
123
155
  }
124
156
 
157
+
158
+
159
+
160
+
125
161
  return num;
126
162
 
127
163
  }
164
+
165
+
166
+
167
+
168
+
169
+
128
170
 
129
171
  ```
130
172
 
@@ -132,86 +174,6 @@
132
174
 
133
175
  ```error
134
176
 
135
- =================================================================
136
177
 
137
- ==29==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x6020000001b0 at pc 0x55e5c0b775bc bp 0x7ffc55a3f070 sp 0x7ffc55a3f060
138
-
139
- READ of size 4 at 0x6020000001b0 thread T0
140
-
141
- #2 0x7f6de42df0b2 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x270b2)
142
-
143
- 0x6020000001b1 is located 0 bytes to the right of 1-byte region [0x6020000001b0,0x6020000001b1)
144
-
145
- allocated by thread T0 here:
146
-
147
- #0 0x7f6de4f24bc8 in malloc (/lib/x86_64-linux-gnu/libasan.so.5+0x10dbc8)
148
-
149
- #3 0x7f6de42df0b2 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x270b2)
150
-
151
- Shadow bytes around the buggy address:
152
-
153
- 0x0c047fff7fe0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
154
-
155
- 0x0c047fff7ff0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
156
-
157
- 0x0c047fff8000: fa fa 00 04 fa fa fd fa fa fa fd fa fa fa fd fa
158
-
159
- 0x0c047fff8010: fa fa 00 fa fa fa fd fa fa fa fd fa fa fa fd fa
160
-
161
- 0x0c047fff8020: fa fa fd fa fa fa fd fa fa fa fd fa fa fa 00 00
162
-
163
- =>0x0c047fff8030: fa fa fd fa fa fa[01]fa fa fa 04 fa fa fa fa fa
164
-
165
- 0x0c047fff8040: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
166
-
167
- 0x0c047fff8050: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
168
-
169
- 0x0c047fff8060: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
170
-
171
- 0x0c047fff8070: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
172
-
173
- 0x0c047fff8080: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
174
-
175
- Shadow byte legend (one shadow byte represents 8 application bytes):
176
-
177
- Addressable: 00
178
-
179
- Partially addressable: 01 02 03 04 05 06 07
180
-
181
- Heap left redzone: fa
182
-
183
- Freed heap region: fd
184
-
185
- Stack left redzone: f1
186
-
187
- Stack mid redzone: f2
188
-
189
- Stack right redzone: f3
190
-
191
- Stack after return: f5
192
-
193
- Stack use after scope: f8
194
-
195
- Global redzone: f9
196
-
197
- Global init order: f6
198
-
199
- Poisoned by user: f7
200
-
201
- Container overflow: fc
202
-
203
- Array cookie: ac
204
-
205
- Intra object redzone: bb
206
-
207
- ASan internal: fe
208
-
209
- Left alloca redzone: ca
210
-
211
- Right alloca redzone: cb
212
-
213
- Shadow gap: cc
214
-
215
- ==29==ABORTING
216
178
 
217
179
  ```

4

コード 修正しました。

2021/09/23 09:50

投稿

alizona
alizona

スコア126

test CHANGED
File without changes
test CHANGED
@@ -94,6 +94,8 @@
94
94
 
95
95
  ```C
96
96
 
97
+
98
+
97
99
  int removeDuplicates(int* nums, int numsSize){
98
100
 
99
101
 
@@ -106,17 +108,15 @@
106
108
 
107
109
 
108
110
 
109
- for (i = 0;i < numsSize;i++) {
111
+ for (i = 1;i < numsSize;i++) {
110
-
111
- if(i!=0){
112
+
112
-
113
+
114
+
113
- if(nums[i-1]!=nums[i]){
115
+ if(nums[i-1]!=nums[i]){
114
-
116
+
115
- nums[num]=nums[i];
117
+ nums[num]=nums[i];
116
-
118
+
117
- num++;
119
+ num++;
118
-
119
- }
120
120
 
121
121
  }
122
122
 

3

コードを編集したので、下に追記しました。エラ〜コードも追記しました。

2021/09/23 07:37

投稿

alizona
alizona

スコア126

test CHANGED
File without changes
test CHANGED
@@ -89,3 +89,129 @@
89
89
  }
90
90
 
91
91
  ```
92
+
93
+
94
+
95
+ ```C
96
+
97
+ int removeDuplicates(int* nums, int numsSize){
98
+
99
+
100
+
101
+ int i;
102
+
103
+ int num=1;
104
+
105
+
106
+
107
+
108
+
109
+ for (i = 0;i < numsSize;i++) {
110
+
111
+ if(i!=0){
112
+
113
+ if(nums[i-1]!=nums[i]){
114
+
115
+ nums[num]=nums[i];
116
+
117
+ num++;
118
+
119
+ }
120
+
121
+ }
122
+
123
+ }
124
+
125
+ return num;
126
+
127
+ }
128
+
129
+ ```
130
+
131
+
132
+
133
+ ```error
134
+
135
+ =================================================================
136
+
137
+ ==29==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x6020000001b0 at pc 0x55e5c0b775bc bp 0x7ffc55a3f070 sp 0x7ffc55a3f060
138
+
139
+ READ of size 4 at 0x6020000001b0 thread T0
140
+
141
+ #2 0x7f6de42df0b2 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x270b2)
142
+
143
+ 0x6020000001b1 is located 0 bytes to the right of 1-byte region [0x6020000001b0,0x6020000001b1)
144
+
145
+ allocated by thread T0 here:
146
+
147
+ #0 0x7f6de4f24bc8 in malloc (/lib/x86_64-linux-gnu/libasan.so.5+0x10dbc8)
148
+
149
+ #3 0x7f6de42df0b2 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x270b2)
150
+
151
+ Shadow bytes around the buggy address:
152
+
153
+ 0x0c047fff7fe0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
154
+
155
+ 0x0c047fff7ff0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
156
+
157
+ 0x0c047fff8000: fa fa 00 04 fa fa fd fa fa fa fd fa fa fa fd fa
158
+
159
+ 0x0c047fff8010: fa fa 00 fa fa fa fd fa fa fa fd fa fa fa fd fa
160
+
161
+ 0x0c047fff8020: fa fa fd fa fa fa fd fa fa fa fd fa fa fa 00 00
162
+
163
+ =>0x0c047fff8030: fa fa fd fa fa fa[01]fa fa fa 04 fa fa fa fa fa
164
+
165
+ 0x0c047fff8040: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
166
+
167
+ 0x0c047fff8050: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
168
+
169
+ 0x0c047fff8060: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
170
+
171
+ 0x0c047fff8070: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
172
+
173
+ 0x0c047fff8080: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
174
+
175
+ Shadow byte legend (one shadow byte represents 8 application bytes):
176
+
177
+ Addressable: 00
178
+
179
+ Partially addressable: 01 02 03 04 05 06 07
180
+
181
+ Heap left redzone: fa
182
+
183
+ Freed heap region: fd
184
+
185
+ Stack left redzone: f1
186
+
187
+ Stack mid redzone: f2
188
+
189
+ Stack right redzone: f3
190
+
191
+ Stack after return: f5
192
+
193
+ Stack use after scope: f8
194
+
195
+ Global redzone: f9
196
+
197
+ Global init order: f6
198
+
199
+ Poisoned by user: f7
200
+
201
+ Container overflow: fc
202
+
203
+ Array cookie: ac
204
+
205
+ Intra object redzone: bb
206
+
207
+ ASan internal: fe
208
+
209
+ Left alloca redzone: ca
210
+
211
+ Right alloca redzone: cb
212
+
213
+ Shadow gap: cc
214
+
215
+ ==29==ABORTING
216
+
217
+ ```

2

linkの追加

2021/09/23 06:37

投稿

alizona
alizona

スコア126

test CHANGED
File without changes
test CHANGED
@@ -1,4 +1,8 @@
1
- numsという配列を並び替える問題で、Time Limit Exceededというエラーが出ます。
1
+ numsという配列を並び替える問題で、LeetCode内でTime Limit Exceededというエラーが出ます。
2
+
3
+
4
+
5
+ [LeetCodeの問題です。](https://leetcode.com/problems/remove-duplicates-from-sorted-array/)
2
6
 
3
7
 
4
8
 

1

単語の修正

2021/09/23 06:05

投稿

alizona
alizona

スコア126

test CHANGED
File without changes
test CHANGED
@@ -56,7 +56,7 @@
56
56
 
57
57
 
58
58
 
59
- for(j=i; j<numsSize-1;j++){//重複が確認されたので、全ての要素を左に詰めるための配列
59
+ for(j=i; j<numsSize-1;j++){//重複が確認されたので、全ての要素を左に詰めるためのfor loop
60
60
 
61
61
  nums[j]=nums[j+1];
62
62