Wireshark mailing list archives
ep_alloc overused?
From: Jakub Zawadzki <darkjames () darkjames ath cx>
Date: Sun, 25 Oct 2009 00:03:37 +0200
Hello list, Recently I'm browsing through wireshark sources, and in many dissectors (this is example from packet-epl_v1.c) there's code like this: from dissect_epl_v1: info_str = ep_alloc(200); info_str[0] = 0; switch (epl_v1_service){ case EPL_V1_SOC: g_snprintf(info_str, 200, "SoC dest = %3d src = %3d ", epl_v1_dest, epl_v1_src); break; case EPL_V1_EOC: g_snprintf(info_str, 200, "EoC dest = %3d src = %3d ", epl_v1_dest, epl_v1_src); break; case EPL_V1_PREQ: g_snprintf(info_str, 200, "PReq dest = %3d src = %3d ", epl_v1_dest, epl_v1_src); break; /* and so ... */ } if(check_col(pinfo->cinfo, COL_INFO)) col_add_str(pinfo->cinfo, COL_INFO, info_str); Code is ok, and works fine... But I've got 3 questions: 1/ There's ep_strdup_printf() function - shouldn't it be used in cases like it? (IMHO best way) 2/ Why ep memory is used in first place, shouldn't be gchar info_str[200]; used instead of gchar *info_str = ep_alloc(200); ? 3/ 200 bytes buffer is overkill - shouldn't g_sprintf() be used? (if programmer make mistake in buffer size canary check will abort program) or both 4 ways are ok, and there's no best one? :) Regards. ___________________________________________________________________________ Sent via: Wireshark-dev mailing list <wireshark-dev () wireshark org> Archives: http://www.wireshark.org/lists/wireshark-dev Unsubscribe: https://wireshark.org/mailman/options/wireshark-dev mailto:wireshark-dev-request () wireshark org?subject=unsubscribe
Current thread:
- ep_alloc overused? Jakub Zawadzki (Oct 24)
- Re: ep_alloc overused? Guy Harris (Oct 24)
- Re: ep_alloc overused? Jakub Zawadzki (Oct 25)
- Re: ep_alloc overused? Jakub Zawadzki (Oct 25)
- Re: ep_alloc overused? Guy Harris (Oct 24)