Skip to content

Commit

Permalink
Fix a bunch of warnings from -Wall.
Browse files Browse the repository at this point in the history
Several comparisons between signed and non-signed integers. Fixed by using size_t instead of int in a number of places.
One unused variable. Removed.
No return value from gridfs_mknod(). It doesn't do anything yet, so just return 0.
  • Loading branch information
Imroy committed Nov 25, 2013
1 parent 914804b commit 016b192
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 15 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
CXXFLAGS += -g -std=c++11 -D_FILE_OFFSET_BITS=64 -I.
CXXFLAGS += -g -std=c++11 -D_FILE_OFFSET_BITS=64 -I. -Wall

MACHINE = $(shell uname -s)

Expand Down
8 changes: 4 additions & 4 deletions local_gridfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ using namespace std;

int LocalGridFile::write(const char *buf, size_t nbyte, off_t offset)
{
int last_chunk = (offset + nbyte) / _chunkSize;
int written = 0;
size_t last_chunk = (offset + nbyte) / _chunkSize;
size_t written = 0;

while(last_chunk > _chunks.size() - 1) {
char *new_buf = new char[_chunkSize];
Expand Down Expand Up @@ -37,7 +37,7 @@ int LocalGridFile::write(const char *buf, size_t nbyte, off_t offset)
chunk_num++;
}

_length = max(_length, (int)offset + written);
_length = max(_length, offset + written);
_dirty = true;

return written;
Expand All @@ -46,7 +46,7 @@ int LocalGridFile::write(const char *buf, size_t nbyte, off_t offset)
int LocalGridFile::read(char* buf, size_t size, off_t offset)
{
size_t len = 0;
int chunk_num = offset / _chunkSize;
size_t chunk_num = offset / _chunkSize;

while(len < size && chunk_num < _chunks.size()) {
const char* chunk = _chunks[chunk_num];
Expand Down
4 changes: 2 additions & 2 deletions local_gridfile.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const unsigned int DEFAULT_CHUNK_SIZE = 256 * 1024;
class LocalGridFile {
public:
LocalGridFile(int chunkSize = DEFAULT_CHUNK_SIZE) :
_chunkSize(chunkSize), _length(0), _dirty(true) {
_length(0), _chunkSize(chunkSize), _dirty(true) {
_chunks.push_back(new char[_chunkSize]);
}

Expand All @@ -38,7 +38,7 @@ class LocalGridFile {
typedef std::shared_ptr<LocalGridFile> ptr;

private:
int _chunkSize, _length;
size_t _length, _chunkSize;
bool _dirty;
std::vector<char*> _chunks;
};
Expand Down
6 changes: 3 additions & 3 deletions operations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ std::shared_ptr<ScopedDbConnection> make_ScopedDbConnection(void) {
}

int gridfs_getattr(const char *path, struct stat *stbuf) {
int res = 0;
memset(stbuf, 0, sizeof(struct stat));

if (strcmp(path, "/") == 0) {
Expand Down Expand Up @@ -251,7 +250,7 @@ int gridfs_listxattr(const char* path, char* list, size_t size) {
if (!file.exists())
return -ENOENT;

int len = 0;
size_t len = 0;
BSONObj metadata = file.getMetadata();
set<string> field_set;
metadata.getFieldNames(field_set);
Expand Down Expand Up @@ -301,7 +300,7 @@ int gridfs_getxattr(const char* path, const char* name, char* value, size_t size
return -ENOATTR;

string field_str = field.toString();
int len = field_str.size() + 1;
size_t len = field_str.size() + 1;
if (size == 0)
return len;
if (len >= size)
Expand Down Expand Up @@ -510,4 +509,5 @@ int gridfs_rename(const char* old_path, const char* new_path) {
int gridfs_mknod(const char *path, mode_t mode, dev_t rdev) {
// POSIX TODO
fprintf(stderr, "MKNOD: %s\n", path);
return 0;
}
10 changes: 5 additions & 5 deletions utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,17 @@ inline const char* fuse_to_mongo_path(const char* path) {
inline const bool is_leaf(const char* path) {
int pp = -1;
int sp = -1;
for(int i=0; i<strlen(path); i++) {
if(path[i] == '/') sp = i;
if(path[i] == '.') pp = i;
for (size_t i = 0; i < strlen(path); i++) {
if (path[i] == '/') sp = i;
if (path[i] == '.') pp = i;
}
return pp > sp;
}

inline const int path_depth(const char* path) {
int sc = 0;
for(int i=0; i<strlen(path); i++) {
if(path[i] == '/') sc++;
for (size_t i=0; i < strlen(path); i++) {
if (path[i] == '/') sc++;
}
return sc;
}
Expand Down

0 comments on commit 016b192

Please sign in to comment.