@@ -17,14 +17,12 @@ limitations under the License.
1717*/
1818
1919#include < driver/ppm_events_public.h>
20- #include < converter/types.h>
21- #include < converter/results.h>
2220#include < converter/table.h>
21+ #include < converter/results.h>
2322#include < converter/debug_macro.h>
2423#include < stdarg.h>
2524#include < cstdio>
2625#include < cassert>
27- #include < unordered_map>
2826#include < string>
2927#include < stdexcept>
3028#include < memory>
@@ -124,7 +122,6 @@ static void push_default_parameter(scap_evt *evt, uint16_t *params_offset, uint8
124122 // Otherwise we will access the wrong entry in the event table.
125123 const struct ppm_event_info *event_info = &(g_event_info[evt->type ]);
126124 uint16_t len = scap_get_size_bytes_from_type (event_info->params [param_num].type );
127- char *ptr = scap_get_default_value_from_type (event_info->params [param_num].type );
128125 uint16_t lens_offset = sizeof (scap_evt) + param_num * sizeof (uint16_t );
129126
130127 PRINT_MESSAGE (
@@ -136,8 +133,11 @@ static void push_default_parameter(scap_evt *evt, uint16_t *params_offset, uint8
136133 *params_offset,
137134 lens_offset);
138135
139- // If value is NULL, the len should be 0
140- memcpy ((char *)evt + *params_offset, ptr, len);
136+ // The default param will be always 0 so we just need to copy the right number of 0 bytes.
137+ // `uint64_t` should be enough for all the types considering that types like CHARBUF, BYTEBUF
138+ // have `len==0`
139+ uint64_t val = 0 ;
140+ memcpy ((char *)evt + *params_offset, (char *)&val, len);
141141 *params_offset += len;
142142 memcpy ((char *)evt + lens_offset, &len, sizeof (uint16_t ));
143143}
@@ -242,7 +242,7 @@ extern "C" void scap_clear_converter_storage() {
242242
243243static conversion_result convert_event (scap_evt *new_evt,
244244 scap_evt *evt_to_convert,
245- const conversion_info * ci,
245+ const conversion_info & ci,
246246 char *error) {
247247 // ///////////////////////////
248248 // Dispatch the action
@@ -251,7 +251,7 @@ static conversion_result convert_event(scap_evt *new_evt,
251251 uint16_t params_offset = 0 ;
252252 int param_to_populate = 0 ;
253253
254- switch (ci-> action ) {
254+ switch (ci. action ) {
255255 case C_ACTION_SKIP:
256256 return CONVERSION_SKIP;
257257
@@ -262,22 +262,22 @@ static conversion_result convert_event(scap_evt *new_evt,
262262 case C_ACTION_ADD_PARAMS:
263263 memcpy (new_evt, evt_to_convert, sizeof (scap_evt));
264264 // The new number of params is the previous one plus the number of conversion instructions.
265- new_evt->nparams = evt_to_convert->nparams + ci-> instr .size ();
265+ new_evt->nparams = evt_to_convert->nparams + ci. instr .size ();
266266 params_offset = copy_old_params (new_evt, evt_to_convert);
267267 param_to_populate = evt_to_convert->nparams ;
268268 break ;
269269
270270 case C_ACTION_CHANGE_TYPE:
271271 memcpy (new_evt, evt_to_convert, sizeof (scap_evt));
272272 // The new number of params is the number of conversion instructions.
273- new_evt->nparams = ci-> instr .size ();
274- new_evt->type = ci-> desired_type ;
273+ new_evt->nparams = ci. instr .size ();
274+ new_evt->type = ci. desired_type ;
275275 params_offset = sizeof (scap_evt) + new_evt->nparams * sizeof (uint16_t );
276276 param_to_populate = 0 ;
277277 break ;
278278
279279 default :
280- snprintf (error, SCAP_LASTERR_SIZE, " Unhandled conversion action '%d'." , ci-> action );
280+ snprintf (error, SCAP_LASTERR_SIZE, " Unhandled conversion action '%d'." , ci. action );
281281 return CONVERSION_ERROR;
282282 }
283283
@@ -293,10 +293,10 @@ static conversion_result convert_event(scap_evt *new_evt,
293293 bool used_enter_event = false ;
294294
295295 // We iterate over the instructions
296- for (int i = 0 ; i < ci-> instr .size (); i++, param_to_populate++) {
296+ for (int i = 0 ; i < ci. instr .size (); i++, param_to_populate++) {
297297 PRINT_MESSAGE (" Instruction n° %d. Param to populate: %d\n " , i, param_to_populate);
298298
299- switch (ci-> instr [i].flags ) {
299+ switch (ci. instr [i].flags ) {
300300 case C_INSTR_FROM_DEFAULT:
301301 tmp_evt = NULL ;
302302 break ;
@@ -329,14 +329,14 @@ static conversion_result convert_event(scap_evt *new_evt,
329329
330330 case C_INSTR_FROM_OLD:
331331 tmp_evt = evt_to_convert;
332- if (tmp_evt->nparams <= ci-> instr [i].param_num ) {
332+ if (tmp_evt->nparams <= ci. instr [i].param_num ) {
333333 // todo!: this sounds like an error but let's see in the future. At the moment we
334334 // fail
335335 snprintf (error,
336336 SCAP_LASTERR_SIZE,
337337 " We want to take parameter '%d' from event '%d' but this event has only "
338338 " '%d' parameters!" ,
339- ci-> instr [i].param_num ,
339+ ci. instr [i].param_num ,
340340 tmp_evt->type ,
341341 tmp_evt->nparams );
342342 return CONVERSION_ERROR;
@@ -347,8 +347,8 @@ static conversion_result convert_event(scap_evt *new_evt,
347347 snprintf (error,
348348 SCAP_LASTERR_SIZE,
349349 " Unknown instruction (flags: %d, param_num: %d)." ,
350- ci-> instr [i].flags ,
351- ci-> instr [i].param_num );
350+ ci. instr [i].flags ,
351+ ci. instr [i].param_num );
352352 return CONVERSION_ERROR;
353353 }
354354
@@ -359,7 +359,7 @@ static conversion_result convert_event(scap_evt *new_evt,
359359 tmp_evt,
360360 ¶ms_offset,
361361 param_to_populate,
362- ci-> instr [i].param_num );
362+ ci. instr [i].param_num );
363363 }
364364 }
365365
@@ -400,5 +400,5 @@ extern "C" conversion_result scap_convert_event(scap_evt *new_evt,
400400 }
401401
402402 // If we reached this point we have for sure an entry in the conversion table.
403- return convert_event (new_evt, evt_to_convert, & g_conversion_table[ conv_key] , error);
403+ return convert_event (new_evt, evt_to_convert, g_conversion_table. at ( conv_key) , error);
404404}
0 commit comments