Skip to content

Commit 90306bb

Browse files
bnoordhuisMyles Borins
authored and
Myles Borins
committed
src: use size_t for http parser array size fields
Make the `num_values_` and `num_fields_` unsigned and remove an erroneous comment. PR-URL: #5969 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent af41a63 commit 90306bb

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

src/node_http_parser.cc

+8-10
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ class Parser : public BaseObject {
189189
if (num_fields_ == num_values_) {
190190
// start of new field name
191191
num_fields_++;
192-
if (num_fields_ == static_cast<int>(arraysize(fields_))) {
192+
if (num_fields_ == arraysize(fields_)) {
193193
// ran out of space - flush to javascript land
194194
Flush();
195195
num_fields_ = 1;
@@ -198,7 +198,7 @@ class Parser : public BaseObject {
198198
fields_[num_fields_ - 1].Reset();
199199
}
200200

201-
CHECK_LT(num_fields_, static_cast<int>(arraysize(fields_)));
201+
CHECK_LT(num_fields_, arraysize(fields_));
202202
CHECK_EQ(num_fields_, num_values_ + 1);
203203

204204
fields_[num_fields_ - 1].Update(at, length);
@@ -214,7 +214,7 @@ class Parser : public BaseObject {
214214
values_[num_values_ - 1].Reset();
215215
}
216216

217-
CHECK_LT(num_values_, static_cast<int>(arraysize(values_)));
217+
CHECK_LT(num_values_, arraysize(values_));
218218
CHECK_EQ(num_values_, num_fields_);
219219

220220
values_[num_values_ - 1].Update(at, length);
@@ -377,11 +377,11 @@ class Parser : public BaseObject {
377377
url_.Save();
378378
status_message_.Save();
379379

380-
for (int i = 0; i < num_fields_; i++) {
380+
for (size_t i = 0; i < num_fields_; i++) {
381381
fields_[i].Save();
382382
}
383383

384-
for (int i = 0; i < num_values_; i++) {
384+
for (size_t i = 0; i < num_values_; i++) {
385385
values_[i].Save();
386386
}
387387
}
@@ -631,11 +631,9 @@ class Parser : public BaseObject {
631631
}
632632

633633
Local<Array> CreateHeaders() {
634-
// num_values_ is either -1 or the entry # of the last header
635-
// so num_values_ == 0 means there's a single header
636634
Local<Array> headers = Array::New(env()->isolate(), 2 * num_values_);
637635

638-
for (int i = 0; i < num_values_; ++i) {
636+
for (size_t i = 0; i < num_values_; ++i) {
639637
headers->Set(2 * i, fields_[i].ToString(env()));
640638
headers->Set(2 * i + 1, values_[i].ToString(env()));
641639
}
@@ -687,8 +685,8 @@ class Parser : public BaseObject {
687685
StringPtr values_[32]; // header values
688686
StringPtr url_;
689687
StringPtr status_message_;
690-
int num_fields_;
691-
int num_values_;
688+
size_t num_fields_;
689+
size_t num_values_;
692690
bool have_flushed_;
693691
bool got_exception_;
694692
Local<Object> current_buffer_;

0 commit comments

Comments
 (0)