aboutsummaryrefslogtreecommitdiffstats
path: root/packet-smpp.c
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2003-06-12 08:33:32 +0000
committerGuy Harris <guy@alum.mit.edu>2003-06-12 08:33:32 +0000
commitee97ce31966f61de148ad85cb229e76a88801b02 (patch)
tree22f7363da150c57eb593a2e5871033e8b8585437 /packet-smpp.c
parent04a87185285865ae91f903662c4bc721f66c8d88 (diff)
Add new routines:
tvb_get_string() - takes a tvbuff, an offset, and a length as arguments, allocates a buffer big enough to hold a string with the specified number of bytes plus an added null terminator (i.e., length+1), copies the specified number of bytes from the tvbuff, at the specified offset, to that buffer and puts in a null terminator, and returns a pointer to that buffer (or throws an exception before allocating the buffer if that many bytes aren't available in the tvbuff); tvb_get_stringz() - takes a tvbuff, an offset, and a pointer to a "gint" as arguments, gets the size of the null-terminated string starting at the specified offset in the tvbuff (throwing an exception if the null terminator isn't found), allocates a buffer big enough to hold that string, copies the string to that buffer, and returns a pointer to that buffer and stores the length of the string (including the terminating null) in the variable pointed to by the "gint" pointer. Replace many pieces of code allocating a buffer and copying a string with calls to "tvb_get_string()" (for one thing, "tvb_get_string()" doesn't require you to remember that the argument to "tvb_get_nstringz0()" is the size of the buffer into which you're copying the string, which might be the length of the string to be copied *plus 1*). Don't use fixed-length buffers for null-terminated strings (even if the code that generates those packets has a #define to limit the length of the string). Use "tvb_get_stringz()", instead. In some cases where a value is fetched but is only used to pass an argument to a "proto_tree_add_XXX" routine, use "proto_tree_add_item()" instead. svn path=/trunk/; revision=7859
Diffstat (limited to 'packet-smpp.c')
-rw-r--r--packet-smpp.c12
1 files changed, 6 insertions, 6 deletions
diff --git a/packet-smpp.c b/packet-smpp.c
index 996f1a59cc..3750b491f4 100644
--- a/packet-smpp.c
+++ b/packet-smpp.c
@@ -2,7 +2,7 @@
* Routines for Short Message Peer to Peer dissection
* Copyright 2001, Tom Uijldert <tom.uijldert@cmg.nl>
*
- * $Id: packet-smpp.c,v 1.11 2003/06/06 01:56:39 guy Exp $
+ * $Id: packet-smpp.c,v 1.12 2003/06/12 08:33:30 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>
@@ -572,7 +572,7 @@ static const value_string vals_its_session_ind[] = {
* \retval FALSE Absolute time
*/
static gboolean
-smpp_mktime(char *datestr, time_t *secs, int *nsecs)
+smpp_mktime(const char *datestr, time_t *secs, int *nsecs)
{
struct tm r_time;
time_t t_diff;
@@ -616,7 +616,7 @@ smpp_mktime(char *datestr, time_t *secs, int *nsecs)
static void
smpp_handle_string(proto_tree *tree, tvbuff_t *tvb, int field, int *offset)
{
- gint len;
+ guint len;
len = tvb_strsize(tvb, *offset);
if (len > 1) {
@@ -660,12 +660,11 @@ static void
smpp_handle_time(proto_tree *tree, tvbuff_t *tvb,
int field, int field_R, int *offset)
{
- char strval[BUFSIZ];
+ char *strval;
gint len;
nstime_t tmptime;
- len = tvb_get_nstringz(tvb, *offset, BUFSIZ, strval);
- len++;
+ strval = tvb_get_stringz(tvb, *offset, &len);
if (*strval)
{
if (smpp_mktime(strval, &tmptime.secs, &tmptime.nsecs))
@@ -673,6 +672,7 @@ smpp_handle_time(proto_tree *tree, tvbuff_t *tvb,
else
proto_tree_add_time(tree, field, tvb, *offset, len, &tmptime);
}
+ g_free(strval);
*offset += len;
}