change some sprintf() to snprintf() in lib code

This commit is contained in:
David Anderson 2016-02-17 22:53:37 -08:00
parent 71832f73dc
commit 1587dbf71a
6 changed files with 26 additions and 26 deletions

View File

@ -526,12 +526,12 @@ void CSimpleProjectPanel::UpdateProjectList() {
std::string CSimpleProjectPanel::GetProjectIconLoc(char* project_url) {
char urlDirectory[256];
char proj_dir[256];
CMainDocument* pDoc = wxGetApp().GetDocument();
PROJECT* project = pDoc->state.lookup_project(project_url);
if (!project) return (std::string)"";
url_to_project_dir(project->master_url, urlDirectory);
return (std::string)urlDirectory + "/stat_icon";
url_to_project_dir(project->master_url, proj_dir, sizeof(proj_dir));
return (std::string)proj_dir + "/stat_icon";
}

View File

@ -885,7 +885,7 @@ wxString CSimpleTaskPanel::GetStatusString(RESULT* result) {
void CSimpleTaskPanel::FindSlideShowFiles(TaskSelectionData *selData) {
RESULT* state_result;
char urlDirectory[1024];
char proj_dir[1024];
char fileName[1024];
char resolvedFileName[1024];
int j;
@ -900,9 +900,9 @@ void CSimpleTaskPanel::FindSlideShowFiles(TaskSelectionData *selData) {
state_result = pDoc->state.lookup_result(selData->result->project_url, selData->result->name);
}
if (state_result) {
url_to_project_dir(state_result->project->master_url, urlDirectory);
url_to_project_dir(state_result->project->master_url, proj_dir, sizeof(proj_dir));
for(j=0; j<99; ++j) {
sprintf(fileName, "%s/slideshow_%s_%02d", urlDirectory, state_result->app->name, j);
sprintf(fileName, "%s/slideshow_%s_%02d", proj_dir, state_result->app->name, j);
if(boinc_resolve_filename(fileName, resolvedFileName, sizeof(resolvedFileName)) == 0) {
if (boinc_file_exists(resolvedFileName)) {
selData->slideShowFileNames.Add(wxString(resolvedFileName,wxConvUTF8));
@ -914,7 +914,7 @@ void CSimpleTaskPanel::FindSlideShowFiles(TaskSelectionData *selData) {
if ( selData->slideShowFileNames.size() == 0 ) {
for(j=0; j<99; ++j) {
sprintf(fileName, "%s/slideshow_%02d", urlDirectory, j);
sprintf(fileName, "%s/slideshow_%02d", proj_dir, j);
if(boinc_resolve_filename(fileName, resolvedFileName, sizeof(resolvedFileName)) == 0) {
if (boinc_file_exists(resolvedFileName)) {
selData->slideShowFileNames.Add(wxString(resolvedFileName,wxConvUTF8));

View File

@ -120,7 +120,7 @@ struct PROJECT_IMAGES {
vector<PROJECT_IMAGES> project_images;
void icon_path(PROJECT* p, char* buf) {
char dir[256];
url_to_project_dir((char*)p->master_url.c_str(), dir);
url_to_project_dir((char*)p->master_url.c_str(), dir, sizeof(dir));
sprintf(buf, "%s/stat_icon", dir);
}
@ -128,7 +128,7 @@ void slideshow(PROJECT* p) {
char dir[256], buf[256];
int i;
url_to_project_dir((char*)p->master_url.c_str(), dir);
url_to_project_dir((char*)p->master_url.c_str(), dir, sizeof(dir));
for (i=0; i<99; i++) {
sprintf(buf, "%s/slideshow_%02d", dir, i);
}
@ -144,7 +144,7 @@ PROJECT_IMAGES* get_project_images(PROJECT* p) {
}
PROJECT_IMAGES pim;
pim.url = p->master_url;
url_to_project_dir((char*)p->master_url.c_str(), dir);
url_to_project_dir((char*)p->master_url.c_str(), dir, sizeof(dir));
sprintf(path, "%s/stat_icon", dir);
boinc_resolve_filename(path, filename, 256);
pim.icon.load_image_file(filename);

View File

@ -523,16 +523,16 @@ string resolve_soft_link(const char* project_dir, const char* file) {
if (!parse_str(buf, "<soft_link>", physical_name, sizeof(physical_name))) {
return string("");
}
sprintf(buf, "../../%s/", project_dir);
snprintf(buf, sizeof(buf), "../../%s/", project_dir);
if (strstr(physical_name, buf) != physical_name) {
return string("");
}
return string(physical_name + strlen(buf));
}
void url_to_project_dir(char* url, char* dir) {
void url_to_project_dir(char* url, char* dir, int dirsize) {
char buf[256];
escape_project_url(url, buf);
sprintf(dir, "%s/%s", PROJECT_DIR, buf);
snprintf(dir, dirsize, "%s/%s", PROJECT_DIR, buf);
}

View File

@ -252,7 +252,7 @@ int parse_graphics_file(FILE* f, GRAPHICS_INFO* gi);
extern int boinc_link(const char* phys_name, const char* logical_name);
extern int boinc_resolve_filename_s(const char*, std::string&);
extern std::string resolve_soft_link(const char* project_dir, const char* file);
extern void url_to_project_dir(char* url, char* dir);
extern void url_to_project_dir(char* url, char* dir, int dirsize);
extern "C" {
#endif

View File

@ -68,13 +68,13 @@ bool parse_bool(const char* buf, const char* tag, bool& result) {
if (!strstr(buf, tag)) {
return false;
}
sprintf(tag2, "<%s/>", tag);
sprintf(tag3, "<%s />", tag);
snprintf(tag2, sizeof(tag2), "<%s/>", tag);
snprintf(tag3, sizeof(tag3), "<%s />", tag);
if (match_tag(buf, tag2) || match_tag(buf, tag3)) {
result = true;
return true;
}
sprintf(tag2, "<%s>", tag);
snprintf(tag2, sizeof(tag2), "<%s>", tag);
if (parse_int(buf, tag2, x)) {
result = (x != 0);
return true;
@ -198,13 +198,13 @@ int dup_element(FILE* in, const char* tag_name, char** pp) {
char buf[256], end_tag[256];
int retval;
sprintf(buf, "<%s>\n", tag_name);
sprintf(end_tag, "</%s>", tag_name);
snprintf(buf, sizeof(buf), "<%s>\n", tag_name);
snprintf(end_tag, sizeof(end_tag), "</%s>", tag_name);
char* p = strdup(buf);
while (fgets(buf, 256, in)) {
if (strstr(buf, end_tag)) {
sprintf(buf, "</%s>\n", tag_name);
snprintf(buf, sizeof(buf), "</%s>\n", tag_name);
retval = strcatdup(p, buf);
if (retval) return retval;
*pp = p;
@ -314,7 +314,7 @@ void extract_venue(const char* in, const char* venue_name, char* out, int len) {
const char* p, *q;
char* wp;
char buf[256];
sprintf(buf, "<venue name=\"%s\">", venue_name);
snprintf(buf, sizeof(buf), "<venue name=\"%s\">", venue_name);
p = strstr(in, buf);
if (p) {
// prefs contain the specified venue
@ -366,7 +366,7 @@ void non_ascii_escape(const char* in, char* out, int len) {
int x = (int) *in;
x &= 0xff; // just in case
if (x>127) {
sprintf(buf, "&#%d;", x);
snprintf(buf, sizeof(buf), "&#%d;", x);
strcpy(p, buf);
p += strlen(buf);
} else {
@ -397,7 +397,7 @@ void xml_escape(const char* in, char* out, int len) {
strcpy(p, "&amp;");
p += 5;
} else if (x>127) {
sprintf(buf, "&#%d;", x);
snprintf(buf, sizeof(buf), "&#%d;", x);
strcpy(p, buf);
p += strlen(buf);
} else if (x<32) {
@ -405,7 +405,7 @@ void xml_escape(const char* in, char* out, int len) {
case 9:
case 10:
case 13:
sprintf(buf, "&#%d;", x);
snprintf(buf, sizeof(buf), "&#%d;", x);
strcpy(p, buf);
p += strlen(buf);
break;
@ -879,7 +879,7 @@ void XML_PARSER::skip_unexpected(
);
}
if (strchr(start_tag, '/')) return;
sprintf(end_tag, "/%s", start_tag);
snprintf(end_tag, sizeof(end_tag), "/%s", start_tag);
while (1) {
int c;
@ -913,7 +913,7 @@ int XML_PARSER::copy_element(string& out) {
out = "<";
out += parsed_tag;
out += ">";
sprintf(end_tag, "</%s>", parsed_tag);
snprintf(end_tag, sizeof(end_tag), "</%s>", parsed_tag);
int retval = element_contents(end_tag, buf, sizeof(buf));
if (retval) return retval;
out += buf;