Skip to content

Commit 20bb92f

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 2fd8be2 commit 20bb92f

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
@@ -193,7 +193,7 @@ class Parser : public AsyncWrap {
193193
if (num_fields_ == num_values_) {
194194
// start of new field name
195195
num_fields_++;
196-
if (num_fields_ == static_cast<int>(arraysize(fields_))) {
196+
if (num_fields_ == arraysize(fields_)) {
197197
// ran out of space - flush to javascript land
198198
Flush();
199199
num_fields_ = 1;
@@ -202,7 +202,7 @@ class Parser : public AsyncWrap {
202202
fields_[num_fields_ - 1].Reset();
203203
}
204204

205-
CHECK_LT(num_fields_, static_cast<int>(arraysize(fields_)));
205+
CHECK_LT(num_fields_, arraysize(fields_));
206206
CHECK_EQ(num_fields_, num_values_ + 1);
207207

208208
fields_[num_fields_ - 1].Update(at, length);
@@ -218,7 +218,7 @@ class Parser : public AsyncWrap {
218218
values_[num_values_ - 1].Reset();
219219
}
220220

221-
CHECK_LT(num_values_, static_cast<int>(arraysize(values_)));
221+
CHECK_LT(num_values_, arraysize(values_));
222222
CHECK_EQ(num_values_, num_fields_);
223223

224224
values_[num_values_ - 1].Update(at, length);
@@ -385,11 +385,11 @@ class Parser : public AsyncWrap {
385385
url_.Save();
386386
status_message_.Save();
387387

388-
for (int i = 0; i < num_fields_; i++) {
388+
for (size_t i = 0; i < num_fields_; i++) {
389389
fields_[i].Save();
390390
}
391391

392-
for (int i = 0; i < num_values_; i++) {
392+
for (size_t i = 0; i < num_values_; i++) {
393393
values_[i].Save();
394394
}
395395
}
@@ -637,12 +637,10 @@ class Parser : public AsyncWrap {
637637
}
638638

639639
Local<Array> CreateHeaders() {
640-
// num_values_ is either -1 or the entry # of the last header
641-
// so num_values_ == 0 means there's a single header
642640
Local<Array> headers = Array::New(env()->isolate());
643641
Local<Function> fn = env()->push_values_to_array_function();
644642
Local<Value> argv[NODE_PUSH_VAL_TO_ARRAY_MAX * 2];
645-
int i = 0;
643+
size_t i = 0;
646644

647645
do {
648646
size_t j = 0;
@@ -702,8 +700,8 @@ class Parser : public AsyncWrap {
702700
StringPtr values_[32]; // header values
703701
StringPtr url_;
704702
StringPtr status_message_;
705-
int num_fields_;
706-
int num_values_;
703+
size_t num_fields_;
704+
size_t num_values_;
707705
bool have_flushed_;
708706
bool got_exception_;
709707
Local<Object> current_buffer_;

0 commit comments

Comments
 (0)