Skip to content

Commit

Permalink
- C++ code: use MAXPATHLEN for char arrays that hold paths
Browse files Browse the repository at this point in the history
svn path=/trunk/boinc/; revision=25659
  • Loading branch information
davidpanderson committed May 9, 2012
1 parent 8b5b765 commit 32a08d2
Show file tree
Hide file tree
Showing 50 changed files with 115 additions and 99 deletions.
8 changes: 4 additions & 4 deletions api/boinc_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -849,7 +849,7 @@ int resume_activities() {
}

static void handle_upload_file_status() {
char path[256], buf[256], log_name[256], *p, log_buf[256];
char path[MAXPATHLEN], buf[256], log_name[256], *p, log_buf[256];
std::string filename;
int status;

Expand Down Expand Up @@ -1000,7 +1000,7 @@ struct GRAPHICS_APP {
void run(char* path) {
int argc;
char* argv[4];
char abspath[1024];
char abspath[MAXPATHLEN];
#ifdef _WIN32
GetFullPathName(path, 1024, abspath, NULL);
#else
Expand Down Expand Up @@ -1039,7 +1039,7 @@ static bool have_graphics_app;
// The following is for backwards compatibility with version 5 clients.
//
static inline void handle_graphics_messages() {
static char graphics_app_path[1024];
static char graphics_app_path[MAXPATHLEN];
char buf[MSG_CHANNEL_SIZE];
GRAPHICS_MSG m;
static bool first=true;
Expand Down Expand Up @@ -1389,7 +1389,7 @@ int boinc_fraction_done(double x) {

int boinc_receive_trickle_down(char* buf, int len) {
std::string filename;
char path[256];
char path[MAXPATHLEN];

if (!options.handle_trickle_downs) return false;

Expand Down
3 changes: 3 additions & 0 deletions checkin_notes
Original file line number Diff line number Diff line change
Expand Up @@ -3750,4 +3750,7 @@ Bernd 9 May 2012
boinc_db.cpp


David 9 May 2012
- C++ code: use MAXPATHLEN for char arrays that hold paths

(many .cpp files)
12 changes: 6 additions & 6 deletions client/app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ void ACTIVE_TASK_SET::get_memory_usage() {
// Move it from slot dir to project dir
//
int ACTIVE_TASK::move_trickle_file() {
char project_dir[256], new_path[1024], old_path[1024];
char project_dir[256], new_path[MAXPATHLEN], old_path[MAXPATHLEN];
int retval;

get_project_dir(result->project, project_dir, sizeof(project_dir));
Expand All @@ -440,7 +440,7 @@ int ACTIVE_TASK::current_disk_usage(double& size) {
unsigned int i;
int retval;
FILE_INFO* fip;
char path[1024];
char path[MAXPATHLEN];

retval = dir_size(slot_dir, size);
if (retval) return retval;
Expand All @@ -464,7 +464,7 @@ bool ACTIVE_TASK_SET::is_slot_in_use(int slot) {
}

bool ACTIVE_TASK_SET::is_slot_dir_in_use(char* dir) {
char path[1024];
char path[MAXPATHLEN];
unsigned int i;
for (i=0; i<active_tasks.size(); i++) {
get_slot_dir(active_tasks[i]->slot, path, sizeof(path));
Expand All @@ -479,7 +479,7 @@ bool ACTIVE_TASK_SET::is_slot_dir_in_use(char* dir) {
void ACTIVE_TASK::get_free_slot(RESULT* rp) {
#ifndef SIM
int j, retval;
char path[1024];
char path[MAXPATHLEN];

for (j=0; ; j++) {
if (gstate.active_tasks.is_slot_in_use(j)) continue;
Expand Down Expand Up @@ -886,7 +886,7 @@ void ACTIVE_TASK_SET::report_overdue() {
//
int ACTIVE_TASK::handle_upload_files() {
std::string filename;
char buf[256], path[1024];
char buf[256], path[MAXPATHLEN];
int retval;

DirScanner dirscan(slot_dir);
Expand Down Expand Up @@ -942,7 +942,7 @@ void ACTIVE_TASK_SET::network_available() {
}

void ACTIVE_TASK::upload_notify_app(const FILE_INFO* fip, const FILE_REF* frp) {
char path[256];
char path[MAXPATHLEN];
sprintf(path, "%s/%s%s", slot_dir, UPLOAD_FILE_STATUS_PREFIX, frp->open_name);
FILE* f = boinc_fopen(path, "w");
if (!f) return;
Expand Down
10 changes: 5 additions & 5 deletions client/app_control.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -529,13 +529,13 @@ void ACTIVE_TASK::handle_exited_app(int stat) {
}

bool ACTIVE_TASK::finish_file_present() {
char path[256];
char path[MAXPATHLEN];
sprintf(path, "%s/%s", slot_dir, BOINC_FINISH_CALLED_FILE);
return (boinc_file_exists(path) != 0);
}

bool ACTIVE_TASK::temporary_exit_file_present(double& x, char* buf) {
char path[256];
char path[MAXPATHLEN];
sprintf(path, "%s/%s", slot_dir, TEMPORARY_EXIT_FILE);
FILE* f = fopen(path, "r");
if (!f) return false;
Expand Down Expand Up @@ -805,7 +805,7 @@ int ACTIVE_TASK::abort_task(int exit_status, const char* msg) {
//
int ACTIVE_TASK::read_stderr_file() {
char* buf1, *buf2;
char path[256];
char path[MAXPATHLEN];

// truncate stderr output to the last 63KB;
// it's unlikely that more than that will be useful
Expand Down Expand Up @@ -1341,7 +1341,7 @@ void ACTIVE_TASK_SET::get_msgs() {
// (this avoids rewriting the state file on each checkpoint)
//
void ACTIVE_TASK::write_task_state_file() {
char path[1024];
char path[MAXPATHLEN];
sprintf(path, "%s/%s", slot_dir, TASK_STATE_FILENAME);
FILE* f = fopen(path, "w");
if (!f) return;
Expand All @@ -1366,7 +1366,7 @@ void ACTIVE_TASK::write_task_state_file() {
// then the main state file
//
void ACTIVE_TASK::read_task_state_file() {
char buf[4096], path[1024], s[1024];
char buf[4096], path[MAXPATHLEN], s[1024];
sprintf(path, "%s/%s", slot_dir, TASK_STATE_FILENAME);
FILE* f = fopen(path, "r");
if (!f) return;
Expand Down
18 changes: 9 additions & 9 deletions client/app_start.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ int ACTIVE_TASK::get_shmem_seg_name() {
if (!shm_handle) return ERR_SHMGET;
sprintf(shmem_seg_name, "boinc_%d", i);
#else
char init_data_path[256];
char init_data_path[MAXPATHLEN];
#ifndef __EMX__
// shmem_seg_name is not used with mmap() shared memory
if (app_version->api_major_version() >= 6) {
Expand Down Expand Up @@ -195,7 +195,7 @@ int ACTIVE_TASK::get_shmem_seg_name() {
}

void ACTIVE_TASK::init_app_init_data(APP_INIT_DATA& aid) {
char project_dir[256], project_path[256];
char project_dir[256], project_path[MAXPATHLEN];

aid.major_version = BOINC_MAJOR_VERSION;
aid.minor_version = BOINC_MINOR_VERSION;
Expand Down Expand Up @@ -279,7 +279,7 @@ void ACTIVE_TASK::init_app_init_data(APP_INIT_DATA& aid) {
//
int ACTIVE_TASK::write_app_init_file(APP_INIT_DATA& aid) {
FILE *f;
char init_data_path[256];
char init_data_path[MAXPATHLEN];

sprintf(init_data_path, "%s/%s", slot_dir, INIT_DATA_FILE);

Expand Down Expand Up @@ -308,7 +308,7 @@ static int create_dirs_for_logical_name(
const char* name, const char* slot_dir
) {
char buf[1024];
char dir_path[1024];
char dir_path[MAXPATHLEN];
int retval;

strcpy(buf, name);
Expand Down Expand Up @@ -353,7 +353,7 @@ bool ACTIVE_TASK::must_copy_file(FILE_REF& fref, bool is_io_file) {
int ACTIVE_TASK::setup_file(
FILE_INFO* fip, FILE_REF& fref, char* file_path, bool input, bool is_io_file
) {
char link_path[256], rel_file_path[256], open_name[256];
char link_path[MAXPATHLEN], rel_file_path[MAXPATHLEN], open_name[256];
int retval;
PROJECT* project = result->project;

Expand Down Expand Up @@ -426,7 +426,7 @@ int ACTIVE_TASK::link_user_files() {
unsigned int i;
FILE_REF fref;
FILE_INFO* fip;
char file_path[1024];
char file_path[MAXPATHLEN];

for (i=0; i<project->user_files.size(); i++) {
fref = project->user_files[i];
Expand Down Expand Up @@ -481,7 +481,7 @@ int ACTIVE_TASK::copy_output_files() {
// ACTIVE_TASK::task_state is PROCESS_EXECUTING
//
int ACTIVE_TASK::start() {
char exec_name[256], file_path[256], buf[256], exec_path[256];
char exec_name[256], file_path[MAXPATHLEN], buf[256], exec_path[MAXPATHLEN];
char cmdline[80000]; // 64KB plus some extra
unsigned int i;
FILE_REF fref;
Expand Down Expand Up @@ -628,7 +628,7 @@ int ACTIVE_TASK::start() {
PROCESS_INFORMATION process_info;
STARTUPINFO startup_info;
LPVOID environment_block = NULL;
char slotdirpath[256];
char slotdirpath[MAXPATHLEN];
char error_msg[1024];
char error_msg2[1024];

Expand Down Expand Up @@ -1004,7 +1004,7 @@ int ACTIVE_TASK::start() {
}
sprintf(buf, "../../%s", exec_path);
if (g_use_sandbox) {
char switcher_path[100];
char switcher_path[MAXPATHLEN];
sprintf(switcher_path, "../../%s/%s",
SWITCHER_DIR, SWITCHER_FILE_NAME
);
Expand Down
4 changes: 2 additions & 2 deletions client/async_file.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ struct ASYNC_COPY {
ACTIVE_TASK* atp;
FILE_INFO* fip;
FILE* in, *out;
char to_path[1024], temp_path[1024];
char to_path[MAXPATHLEN], temp_path[MAXPATHLEN];

ASYNC_COPY();
~ASYNC_COPY();
Expand All @@ -65,7 +65,7 @@ struct ASYNC_VERIFY {
md5_state_t md5_state;
FILE* in, *out;
gzFile gzin;
char inpath[1024], temp_path[1024], outpath[1024];
char inpath[MAXPATHLEN], temp_path[MAXPATHLEN], outpath[MAXPATHLEN];

ASYNC_VERIFY(){};
~ASYNC_VERIFY(){};
Expand Down
4 changes: 2 additions & 2 deletions client/client_state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1059,7 +1059,7 @@ int CLIENT_STATE::link_app_version(PROJECT* p, APP_VERSION* avp) {
}

if (!strcmp(file_ref.open_name, GRAPHICS_APP_FILENAME)) {
char relpath[512], path[512];
char relpath[MAXPATHLEN], path[MAXPATHLEN];
get_pathname(fip, relpath, sizeof(relpath));
relative_to_absolute(relpath, path);
strlcpy(avp->graphics_exec_path, path, sizeof(avp->graphics_exec_path));
Expand Down Expand Up @@ -1831,7 +1831,7 @@ int CLIENT_STATE::detach_project(PROJECT* project) {
vector<FILE_INFO*>::iterator fi_iter;
FILE_INFO* fip;
PROJECT* p;
char path[256];
char path[MAXPATHLEN];
int retval;

reset_project(project, true);
Expand Down
6 changes: 3 additions & 3 deletions client/client_types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,7 @@ int FILE_INFO::write_gui(MIOFILE& out) {
// delete physical underlying file associated with FILE_INFO
//
int FILE_INFO::delete_file() {
char path[1024];
char path[MAXPATHLEN];

get_pathname(this, path, sizeof(path));
int retval = delete_project_owned_file(path, true);
Expand Down Expand Up @@ -653,7 +653,7 @@ void FILE_INFO::failure_message(string& s) {
#define BUFSIZE 16384
int FILE_INFO::gzip() {
char buf[BUFSIZE];
char inpath[1024], outpath[1024];
char inpath[MAXPATHLEN], outpath[MAXPATHLEN];

get_pathname(this, inpath, sizeof(inpath));
strcpy(outpath, inpath);
Expand Down Expand Up @@ -682,7 +682,7 @@ int FILE_INFO::gzip() {
//
int FILE_INFO::gunzip(char* md5_buf) {
unsigned char buf[BUFSIZE];
char inpath[1024], outpath[1024], tmppath[1024];
char inpath[MAXPATHLEN], outpath[MAXPATHLEN], tmppath[MAXPATHLEN];
md5_state_t md5_state;

md5_init(&md5_state);
Expand Down
3 changes: 2 additions & 1 deletion client/client_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#if !defined(_WIN32) || defined(__CYGWIN32__)
#include <cstdio>
#include <sys/time.h>
#include <sys/param.h>
#endif

#include "md5_file.h"
Expand Down Expand Up @@ -294,7 +295,7 @@ struct APP_VERSION {
PROJECT* project;
std::vector<FILE_REF> app_files;
int ref_cnt;
char graphics_exec_path[512];
char graphics_exec_path[MAXPATHLEN];
char graphics_exec_file[256];
double max_working_set_size;
// max working set of tasks using this app version.
Expand Down
10 changes: 5 additions & 5 deletions client/cs_account.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ using std::sort;
// (which normally is undefined) is valid
//
int PROJECT::write_account_file() {
char path[256];
char path[MAXPATHLEN];
FILE* f;
int retval;

Expand Down Expand Up @@ -183,7 +183,7 @@ int PROJECT::parse_account(FILE* in) {
// (so that we know the host venue)
//
int PROJECT::parse_account_file_venue() {
char attr_buf[256], venue[256], path[256], buf2[256];
char attr_buf[256], venue[256], path[MAXPATHLEN], buf2[256];
int retval;
bool in_right_venue = false, btemp;

Expand Down Expand Up @@ -258,7 +258,7 @@ int PROJECT::parse_account_file_venue() {
}

int PROJECT::parse_account_file() {
char path[256];
char path[MAXPATHLEN];
int retval;
FILE* f;

Expand Down Expand Up @@ -427,7 +427,7 @@ int CLIENT_STATE::parse_statistics_files() {
}

int PROJECT::write_statistics_file() {
char path[256];
char path[MAXPATHLEN];
FILE* f;
int retval;

Expand Down Expand Up @@ -473,7 +473,7 @@ int CLIENT_STATE::add_project(
const char* master_url, const char* _auth, const char* project_name,
bool attached_via_acct_mgr
) {
char path[256], canonical_master_url[256], auth[256], dir[256];
char path[MAXPATHLEN], canonical_master_url[256], auth[256], dir[256];
PROJECT* project;
FILE* f;
int retval;
Expand Down
2 changes: 1 addition & 1 deletion client/cs_apps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ int CLIENT_STATE::app_finished(ACTIVE_TASK& at) {
#ifndef SIM
FILE_INFO* fip;
unsigned int i;
char path[256];
char path[MAXPATHLEN];
int retval;
double size;

Expand Down
6 changes: 3 additions & 3 deletions client/cs_files.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ int FILE_INFO::verify_file(
// see if we need to unzip it
//
if (download_gzipped && !boinc_file_exists(pathname)) {
char gzpath[256];
char gzpath[MAXPATHLEN];
sprintf(gzpath, "%s.gz", pathname);
if (boinc_file_exists(gzpath) ) {
if (allow_async && nbytes > ASYNC_FILE_THRESHOLD) {
Expand Down Expand Up @@ -401,7 +401,7 @@ bool CLIENT_STATE::create_and_delete_pers_file_xfers() {
// If this was a compressed download, rename .gzt to .gz
//
if (fip->download_gzipped) {
char path[256], from_path[256], to_path[256];
char path[MAXPATHLEN], from_path[MAXPATHLEN], to_path[MAXPATHLEN];
get_pathname(fip, path, sizeof(path));
sprintf(from_path, "%s.gzt", path);
sprintf(to_path, "%s.gz", path);
Expand Down Expand Up @@ -459,7 +459,7 @@ bool CLIENT_STATE::create_and_delete_pers_file_xfers() {
//
void CLIENT_STATE::check_file_existence() {
unsigned int i;
char path[1024];
char path[MAXPATHLEN];

for (i=0; i<file_infos.size(); i++) {
FILE_INFO* fip = file_infos[i];
Expand Down
Loading

0 comments on commit 32a08d2

Please sign in to comment.