コンパイラ警告対策
- size_t は unsigned なので、常に0または+の値となる
- switch() 内の break なし部分に FALLTHROUGH 追加
@@ -1065,7 +1065,7 @@ | ||
1065 | 1065 | ProxyInfo proxy; |
1066 | 1066 | SettingDialog():lock(false) { |
1067 | 1067 | } |
1068 | - | |
1068 | + | |
1069 | 1069 | int open(HWND owner) { |
1070 | 1070 | return Dialog::open(instance().resource_module, IDD_SETTING, owner); |
1071 | 1071 | } |
@@ -1243,7 +1243,7 @@ | ||
1243 | 1243 | if (WSAGetLastError() != WSAEWOULDBLOCK) { |
1244 | 1244 | return SOCKET_ERROR; |
1245 | 1245 | } |
1246 | - // no break | |
1246 | + /* FALLTHROUGH */ // no break | |
1247 | 1247 | case 0: |
1248 | 1248 | end = dst; /* end of stream */ |
1249 | 1249 | break; |
@@ -242,9 +242,7 @@ | ||
242 | 242 | // 返値: |
243 | 243 | // 文字の見つかったインデックス。見つからなければ-1。 |
244 | 244 | int indexOf(char chr, size_t from)const { |
245 | - if (from < 0) | |
246 | - from = 0; | |
247 | - else if (from >= length()) | |
245 | + if (from >= length()) | |
248 | 246 | return -1; |
249 | 247 | const char* found = strchr(string + from, chr); |
250 | 248 | if (found == NULL) |
@@ -267,9 +265,7 @@ | ||
267 | 265 | // 文字列の見つかったインデックス。見つからなければ-1。 |
268 | 266 | // |
269 | 267 | int indexOf(const char* str, size_t from)const { |
270 | - if (from < 0) | |
271 | - from = 0; | |
272 | - else if (from >= length()) | |
268 | + if (from >= length()) | |
273 | 269 | return -1; |
274 | 270 | const char* found = strstr(string + from, str); |
275 | 271 | if (found == NULL) |
@@ -360,7 +356,7 @@ | ||
360 | 356 | // 返値: |
361 | 357 | // 指定の位置にある文字。 |
362 | 358 | char charAt(size_t index)const { |
363 | - return index >= 0 && index < length() ? string[index] : '\0'; | |
359 | + return index < length() ? string[index] : '\0'; | |
364 | 360 | } |
365 | 361 | // 指定の文字を指定の文字に置き換えます。 |
366 | 362 | // 引数: |
@@ -43,7 +43,9 @@ | ||
43 | 43 | }else{ |
44 | 44 | buffer = new char[bufferSize]; |
45 | 45 | } |
46 | - memcpy(buffer, source, validLength); | |
46 | + if (source != NULL) { | |
47 | + memcpy(buffer, source, validLength); | |
48 | + } | |
47 | 49 | memset(buffer + validLength, '\0', bufferSize - validLength); |
48 | 50 | } |
49 | 51 | public: |
@@ -110,7 +112,7 @@ | ||
110 | 112 | // 返値: |
111 | 113 | // 指定の位置の文字。 |
112 | 114 | char charAt(size_t index)const { |
113 | - return index >= 0 && index < validLength ? buffer[index] : '\0'; | |
115 | + return index < validLength ? buffer[index] : '\0'; | |
114 | 116 | } |
115 | 117 | // 指定の位置の文字を取得する。 |
116 | 118 | // 引数: |
@@ -118,9 +120,7 @@ | ||
118 | 120 | // 返値: |
119 | 121 | // 指定の位置の文字の参照。 |
120 | 122 | char& charAt(size_t index) { |
121 | - if (index < 0) { | |
122 | - index = 0; | |
123 | - }else if (index >= validLength) { | |
123 | + if (index >= validLength) { | |
124 | 124 | ensureCapacity(validLength + 1); |
125 | 125 | index = validLength++; |
126 | 126 | } |
@@ -178,8 +178,6 @@ | ||
178 | 178 | // 返値: |
179 | 179 | // 削除結果。 |
180 | 180 | StringBuffer& remove(size_t start, size_t end) { |
181 | - if (start <= 0) | |
182 | - start = 0; | |
183 | 181 | if (start < end) { |
184 | 182 | if (end < validLength){ |
185 | 183 | memcpy(buffer + start, buffer + end, validLength - end); |
@@ -198,8 +196,6 @@ | ||
198 | 196 | // 返値: |
199 | 197 | // 置換結果。 |
200 | 198 | StringBuffer& replace(size_t start, size_t end, const char* source) { |
201 | - if (start < 0) | |
202 | - start = 0; | |
203 | 199 | if (end > validLength) |
204 | 200 | end = validLength; |
205 | 201 | if (start < end) { |
@@ -217,8 +213,6 @@ | ||
217 | 213 | // 返値: |
218 | 214 | // 指定の位置の文字列。 |
219 | 215 | String substring(size_t index)const { |
220 | - if (index < 0) | |
221 | - index = 0; | |
222 | 216 | return String(buffer + index, validLength - index); |
223 | 217 | } |
224 | 218 | // 指定の位置の文字列を取得する。 |
@@ -228,8 +222,6 @@ | ||
228 | 222 | // 返値: |
229 | 223 | // 指定の位置の文字列。 |
230 | 224 | String substring(size_t start, size_t end)const { |
231 | - if (start < 0) | |
232 | - start = 0; | |
233 | 225 | if (end > validLength) |
234 | 226 | end = validLength; |
235 | 227 | return String(buffer + start, end - start); |
@@ -260,9 +252,7 @@ | ||
260 | 252 | // 返値: |
261 | 253 | // 挿入結果。 |
262 | 254 | StringBuffer& insert(size_t index, const char* source, size_t length) { |
263 | - if (index < 0) | |
264 | - index = 0; | |
265 | - else if (index >= validLength) | |
255 | + if (index >= validLength) | |
266 | 256 | index = validLength; |
267 | 257 | size_t oldLength = validLength; |
268 | 258 | ensureCapacity(validLength + length); |