diff --git a/checkin_notes b/checkin_notes
index b1e6eaeb71..581f146a52 100644
--- a/checkin_notes
+++ b/checkin_notes
@@ -4260,3 +4260,13 @@ Rom 30 Apr 2009
David 1 May 2009
- removed outdated translation files; updated template
+
+David 1 May 2009
+ - sample bitwise validator: make it work for binary files
+ fixes #886, #887
+
+ lib/
+ md5_file.h
+ util.cpp,h
+ sched/
+ sample_bitwise_validator.cpp
diff --git a/lib/md5_file.h b/lib/md5_file.h
index 891af1971c..a21b8a2c20 100644
--- a/lib/md5_file.h
+++ b/lib/md5_file.h
@@ -28,8 +28,7 @@ extern int md5_block(const unsigned char* data, int nbytes, char* output);
extern std::string md5_string(const unsigned char* data, int nbytes);
-inline std::string md5_string(std::string const& data)
-{
+inline std::string md5_string(std::string const& data) {
return md5_string((const unsigned char*) data.c_str(), (int)data.size());
}
diff --git a/lib/util.cpp b/lib/util.cpp
index 4dd0f89736..8b31bd39e4 100644
--- a/lib/util.cpp
+++ b/lib/util.cpp
@@ -306,8 +306,8 @@ void boinc_crash() {
// read file (at most max_len chars, if nonzero) into malloc'd buf
//
-int read_file_malloc(const char* path, char*& buf, int max_len, bool tail) {
- int retval, isize;
+int read_file_malloc(const char* path, char*& buf, size_t max_len, bool tail) {
+ int retval;
double size;
retval = file_size(path, size);
@@ -328,7 +328,7 @@ int read_file_malloc(const char* path, char*& buf, int max_len, bool tail) {
size = max_len;
}
#endif
- isize = (int) size;
+ size_t isize = size;
buf = (char*)malloc(isize+1);
size_t n = fread(buf, 1, isize, f);
buf[n] = 0;
@@ -338,7 +338,7 @@ int read_file_malloc(const char* path, char*& buf, int max_len, bool tail) {
// read file (at most max_len chars, if nonzero) into string
//
-int read_file_string(const char* path, string& result, int max_len, bool tail) {
+int read_file_string(const char* path, string& result, size_t max_len, bool tail) {
result.erase();
int retval;
char* buf;
diff --git a/lib/util.h b/lib/util.h
index 7e47b1f158..2548d85cae 100644
--- a/lib/util.h
+++ b/lib/util.h
@@ -70,9 +70,19 @@ extern int boinc_calling_thread_cpu_time(double&);
//
extern void mysql_timestamp(double, char*);
+// fake a crash
+//
extern void boinc_crash();
-extern int read_file_malloc(const char* path, char*&, int max_len=0, bool tail=false);
-extern int read_file_string(const char* path, std::string&, int max_len=0, bool tail=false);
+
+// read files into memory.
+// Use only for non-binary files; returns null-terminated string.
+//
+extern int read_file_malloc(
+ const char* path, char*& result, size_t max_len=0, bool tail=false
+);
+extern int read_file_string(
+ const char* path, std::string& result, size_t max_len=0, bool tail=false
+);
#ifdef _WIN32
diff --git a/sched/sample_bitwise_validator.cpp b/sched/sample_bitwise_validator.cpp
index 07db987c85..0279e35713 100644
--- a/sched/sample_bitwise_validator.cpp
+++ b/sched/sample_bitwise_validator.cpp
@@ -15,7 +15,7 @@
// You should have received a copy of the GNU Lesser General Public License
// along with BOINC. If not, see .
-// A sample validator that grants credit if the majority of results are
+// A sample validator that requires a majority of results to be
// bitwise identical.
// This is useful only if either
// 1) your application does no floating-point math, or
@@ -31,24 +31,15 @@
using std::string;
using std::vector;
-struct FILE_CKSUM {
- string md5sum;
-
- FILE_CKSUM(string& filedata) {
- md5sum = md5_string(filedata);
- }
- ~FILE_CKSUM(){}
-};
-
struct FILE_CKSUM_LIST {
- vector files;
+ vector files; // list of MD5s of files
~FILE_CKSUM_LIST(){}
};
bool files_match(FILE_CKSUM_LIST& f1, FILE_CKSUM_LIST& f2) {
if (f1.files.size() != f2.files.size()) return false;
for (unsigned int i=0; i files;
+ char md5_buf[MD5_LEN];
+ double nbytes;
retval = get_output_file_infos(result, files);
if (retval) {
@@ -67,14 +60,14 @@ int init_result(RESULT& result, void*& data) {
return retval;
}
- string filedata;
for (unsigned int i=0; ifiles.push_back(fc);
+ fcl->files.push_back(string(md5_buf));
}
data = (void*) fcl;
return 0;