aboutsummaryrefslogtreecommitdiffstats
path: root/epan
diff options
context:
space:
mode:
authorStig Bjørlykke <stig@bjorlykke.org>2008-02-03 15:38:20 +0000
committerStig Bjørlykke <stig@bjorlykke.org>2008-02-03 15:38:20 +0000
commit47d744b59da83744623bea39c006eb7e2ec02de9 (patch)
tree17d9ec1526a37c793ee3d7cbd031091d1867dd7f /epan
parente59b5d6b8a963263b0c2dcf163e07b4318737d71 (diff)
More rewrite of prohibited APIs (sprintf, strcpy, strcat).
svn path=/trunk/; revision=24258
Diffstat (limited to 'epan')
-rw-r--r--epan/dissectors/packet-cops.c9
-rw-r--r--epan/filesystem.c18
-rw-r--r--epan/prefs.c2
3 files changed, 10 insertions, 19 deletions
diff --git a/epan/dissectors/packet-cops.c b/epan/dissectors/packet-cops.c
index 181fa50bea..3d73e32283 100644
--- a/epan/dissectors/packet-cops.c
+++ b/epan/dissectors/packet-cops.c
@@ -2634,9 +2634,8 @@ cops_transaction_id(tvbuff_t *tvb, packet_info *pinfo, proto_tree *st, guint8 op
val_to_str(code16,table_cops_dqos_transaction_id, "Unknown (0x%04x)"),code16);
/* Write the right data into the 'info field' on the Gui */
- g_snprintf(info,sizeof(info),"COPS %-20s - ",val_to_str(op_code,cops_op_code_vals, "Unknown"));
- strncat(info,val_to_str(code16,table_cops_dqos_transaction_id, "Unknown"), sizeof(info)-strlen(info));
- info[sizeof(info)-1] = '\0';
+ g_snprintf(info,sizeof(info),"COPS %-20s - %s",val_to_str(op_code,cops_op_code_vals, "Unknown"),
+ val_to_str(code16,table_cops_dqos_transaction_id, "Unknown"));
if (check_col(pinfo->cinfo, COL_INFO)) {
col_clear(pinfo->cinfo, COL_INFO);
@@ -3031,8 +3030,8 @@ cops_mm_transaction_id(tvbuff_t *tvb, packet_info *pinfo, proto_tree *st, guint8
val_to_str(code16,table_cops_mm_transaction_id, "Unknown (0x%04x)"),code16);
/* Write the right data into the 'info field' on the Gui */
- g_snprintf(info,sizeof(info),"COPS %-20s - ",val_to_str(op_code,cops_op_code_vals, "Unknown"));
- strncat(info,val_to_str(code16,table_cops_mm_transaction_id, "Unknown"), sizeof(info)-strlen(info));
+ g_snprintf(info,sizeof(info),"COPS %-20s - %s",val_to_str(op_code,cops_op_code_vals, "Unknown"),
+ val_to_str(code16,table_cops_mm_transaction_id, "Unknown"));
if (check_col(pinfo->cinfo, COL_INFO)) {
col_clear(pinfo->cinfo, COL_INFO);
diff --git a/epan/filesystem.c b/epan/filesystem.c
index 7ad214e9a2..9194226aef 100644
--- a/epan/filesystem.c
+++ b/epan/filesystem.c
@@ -386,10 +386,7 @@ init_progfile_dir(const char *arg0
return g_strdup_printf("getcwd failed: %s\n",
strerror(errno));
}
- path = g_malloc(strlen(curdir) + 1 + strlen(arg0) + 1);
- strcpy(path, curdir);
- strcat(path, "/");
- strcat(path, arg0);
+ path = g_strdup_printf("%s/%s", curdir, arg0);
g_free(curdir);
prog_pathname = path;
} else {
@@ -411,8 +408,8 @@ init_progfile_dir(const char *arg0
+ strlen(arg0) + 1);
memcpy(path, path_start, path_component_len);
path[path_component_len] = '\0';
- strcat(path, "/");
- strcat(path, arg0);
+ strncat(path, "/", 2);
+ strncat(path, arg0, strlen(arg0) + 1);
if (access(path, X_OK) == 0) {
/*
* Found it!
@@ -1140,9 +1137,7 @@ get_persdatafile_dir(void)
/* the "My Captures" sub-directory is created (if it doesn't exist)
by u3util.exe when the U3 Wireshark is first run */
- szPath = g_malloc(strlen(u3devicedocumentpath) + strlen(U3_MY_CAPTURES) + 1);
- strcpy(szPath, u3devicedocumentpath);
- strcat(szPath, U3_MY_CAPTURES);
+ szPath = g_strdup_printf("%s%s", 3devicedocumentpath, U3_MY_CAPTURES);
persdatafile_dir = szPath;
return szPath;
@@ -1192,10 +1187,7 @@ get_home_dir(void)
* This is cached, so we don't need to worry about
* allocating multiple ones of them.
*/
- homestring =
- g_malloc(strlen(homedrive) + strlen(homepath) + 1);
- strcpy(homestring, homedrive);
- strcat(homestring, homepath);
+ homestring = g_strdup_printf("%s%s", homedrive, homepath);
/*
* Trim off any trailing slash or backslash.
diff --git a/epan/prefs.c b/epan/prefs.c
index c5591d52b3..babcaae1a0 100644
--- a/epan/prefs.c
+++ b/epan/prefs.c
@@ -961,7 +961,7 @@ put_string_list(GList *sl)
pref_str[cur_len] = '\n'; cur_len++;
pref_str[cur_len] = '\t'; cur_len++;
}
- sprintf(&pref_str[cur_len], "\"%s\", ", quoted_str);
+ g_snprintf(&pref_str[cur_len], MAX_FMT_PREF_LEN - cur_len, "\"%s\", ", quoted_str);
cur_pos += fmt_len;
cur_len += fmt_len;
}