These functions as you have mentioned have same code ,, so we need to modify it .
I would like to know what will be the solution of this bug as i am new to bug solving
Probably the best way to handle this would be to figure out how and whether cell_t, var_cell_t, and packed_cell_t can (or should) be merged into a single type, and/or to look at dataflow to see if some of those functions can be rewritten to use the others instead.
One wrinkle here is that the *cell_t types need to be very efficient; every piece of data that Tor transmits goes through one of them.
As for eliminating duplicate code in general: I think it's a higher priority to do it for larger functions, and proportionally less valuable to do it for smaller functions.
channel_write_cell(), channel_write_packed_cell() and channel_write_var_cell() are combined into the channel_write() function that takes as a 3rd argument the cell type. That's defined in channel.h as enum with 3 possible values: CELL, PACKED_CELL, VAR_CELL.
In theory, that could work since it's a union and all cell points there but kind of recipe for disaster and bad semantic. What you could do is take a reference on the right cell member of the union while in the switch case and then assign it after.
DG2: Can't you use CELL_QUEUE_* as the cell type?
DG3: Few things. I would rename ctype to cell_type. The switch case MUST have a default branch that you could do a BUG() on and bail. Finally, no need for extra space between the case and the end of the function.
Thanks for this!
Trac: Points: small/medium to 0.1 Reviewer: N/Ato dgoulet Status: needs_review to needs_revision
Please check the new patches. I think you are right about DG1 and also there is an issue about the fact that the dereferencing is not available outside the switch scope. That means that cell would remain of type void*. For these reasons I've moved the (still a bit duplicated) code into the switch cases. I'll add the default case (I wasn't sure how to manage it) and change the ctype.
(I've pull your patch into bug13827_029_01 if anyone wants to see it from git.tpo in my repo.)
DG1: This worries me:
{{{
q.u.var.var_cell = var_cell;
q.u.fixed.cell = cell;
}}}
In theory, that could work since it's a union and all cell points there but kind of recipe for disaster and bad semantic. What you could do is take a reference on the right cell member of the union while in the switch case and then assign it after.
DG2: Can't you use CELL_QUEUE_* as the cell type?
DG3: Few things. I would rename ctype to cell_type. The switch case MUST have a default branch that you could do a BUG() on and bail. Finally, no need for extra space between the case and the end of the function.