Opened 9 years ago

Closed 8 years ago

#836 closed defect (duplicate)

operator[] on an empty vector

Reported by: fdupont Owned by: jinmei
Priority: medium Milestone:
Component: Unclassified Version:
Keywords: Cc:
CVSS Scoring: Parent Tickets:
Sensitive: no Defect Severity: N/A
Sub-Project: DNS Feature Depending on Ticket:
Estimated Difficulty: 0.0 Add Hours to Ticket: 0
Total Hours: 0 Internal?: no

Description

&v[0] where v is the empty vector raises a runtime error on Windows.
IMHO Windows is right and the vector should be checked before.

Subtickets

Attachments (1)

basetests.diff (1.1 KB) - added by jinmei 9 years ago.

Download all attachments as: .zip

Change History (9)

comment:1 follow-up: Changed 9 years ago by fdupont

branch trac836 ready for review.

comment:2 Changed 9 years ago by jinmei

  • Owner set to jinmei
  • Status changed from new to accepted

Changed 9 years ago by jinmei

comment:3 follow-up: Changed 9 years ago by jinmei

I'd suggest a counter proposal. See the attached patch.

p.s. this line surprised me, I suspect you didn't compile your patch:-)

+    if (output.size() == ) {

comment:4 Changed 9 years ago by jinmei

  • Status changed from accepted to assigned

hmm, I cannot reassign the ticket to Francis via the pulldown menu. So I'll keep it assigned to me.

comment:5 in reply to: ↑ 3 Changed 9 years ago by fdupont

Replying to jinmei:

I'd suggest a counter proposal. See the attached patch.

p.s. this line surprised me, I suspect you didn't compile your patch:-)

=> I compiled it but the cut and paste left the 0 behind...

BTW your proposed fixed is simpler and works too (I checked).

comment:6 in reply to: ↑ 1 ; follow-up: Changed 9 years ago by fdupont

Found another case: isc::dns::Generic::Generic with rdata_len == 0:

vector<uint8_t> data(rdata_len);
buffer.readData(&data![0], rdata_len);

First line builds an empty vector, second crashes...
in src/lib/dns/rdata.cc line 113

comment:7 in reply to: ↑ 6 Changed 9 years ago by fdupont

And also in rdata.cc: compare_internal():

if ((cmp = memcmp(&lhs.data_![0], &rhs.data_![0], len))

!= 0) {
return (cmp);

(fix: add (this_len > 0) && (other_len > 0) before)

comment:8 Changed 8 years ago by jinmei

  • Defect Severity set to N/A
  • Resolution set to duplicate
  • Status changed from assigned to closed
  • Sub-Project set to DNS

This should have been fixed with #838. Closing this one.

Note: See TracTickets for help on using tickets.