Skip to content

Commit

Permalink
Merge pull request #206 from tjeb/ldnswalk-improvement
Browse files Browse the repository at this point in the history
improve 'next-label' algorithm in ldns-walk
  • Loading branch information
wtoorop authored Jul 12, 2024
2 parents a05aedb + 22a8906 commit 72dcf7d
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions examples/ldns-walk.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,31 +38,30 @@ create_dname_plus_1(ldns_rdf *dname)
size_t i;

ldns_dname2canonical(dname);
labellen = ldns_rdf_data(dname)[0];
if (verbosity >= 3) {
printf("Create +e for ");
ldns_rdf_print(stdout, dname);
printf("\n");
}
if (labellen < 63) {
wire = malloc(ldns_rdf_size(dname) + 1);
if (ldns_rdf_size(dname) < LDNS_MAX_DOMAINLEN) {
wire = malloc(ldns_rdf_size(dname) + 2);
if (!wire) {
fprintf(stderr, "Malloc error: out of memory?\n");
exit(127);
}
wire[0] = labellen + 1;
memcpy(&wire[1], ldns_rdf_data(dname) + 1, labellen);
memcpy(&wire[labellen+1], ldns_rdf_data(dname) + labellen, ldns_rdf_size(dname) - labellen);
wire[labellen+1] = (uint8_t) '\000';
wire[0] = (uint8_t) 1;
wire[1] = (uint8_t) '\000';
memcpy(&wire[2], ldns_rdf_data(dname), ldns_rdf_size(dname));
pos = 0;
status = ldns_wire2dname(&newdname, wire, ldns_rdf_size(dname) + 1, &pos);
status = ldns_wire2dname(&newdname, wire, ldns_rdf_size(dname) + 2, &pos);
free(wire);
} else {
wire = malloc(ldns_rdf_size(dname));
if (!wire) {
fprintf(stderr, "Malloc error: out of memory?\n");
exit(127);
}
labellen = ldns_rdf_data(dname)[0];
wire[0] = labellen;
memcpy(&wire[1], ldns_rdf_data(dname) + 1, labellen);
memcpy(&wire[labellen], ldns_rdf_data(dname) + labellen, ldns_rdf_size(dname) - labellen);
Expand Down

0 comments on commit 72dcf7d

Please sign in to comment.