-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature #2
base: master
Are you sure you want to change the base?
Feature #2
Conversation
People managing packages at Ubuntu are "special". They decided that putting an old as hell 6th version gcc in a new distro would be a great idea. To fix the problem, you need to install a fresh gcc: I agree, the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for contributing!
It'll be able to merge your changes after you fix problems mentioned in review
Also please pay attention to your git history. Squash your commits before PRing to keep project history clean
@@ -3,7 +3,7 @@ DEPS=simpledb | |||
LIBS=zlib | |||
|
|||
CC=gcc | |||
CFLAGS=-O2 -Wall -Wextra -Wpedantic -Werror |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree that getting rid of -Werror
seems good idea. But other options are useful indeed.
CFLAGS=-O2 -Wall -Wextra -Wpedantic
db.c
Outdated
@@ -229,10 +230,10 @@ int main(int argc, char *argv[]) { | |||
} | |||
|
|||
if (args.query) { | |||
char *qval = strdup(args.query); | |||
char *qval = malloc(sizeof(args.query)); /* Function in ANSI C, more portable */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
args.query
is a string. So what strdup
essentially does is allocates the required memory and copies passed string there, returning the starting address. See man 3 strdup
for more.
A sizeof
is not a function, but operator. And it would never ever calculate the length of a string. Try adding a printf("sizeof(args.query)=%d chars", (int) sizeof args.query);
and see the output.
We don't care about backwards compatibility, so no need for old ANSI C and K&R C stuff, use the latest things available
db.c
Outdated
@@ -247,7 +248,7 @@ int main(int argc, char *argv[]) { | |||
int lerr = E_OK; | |||
switch(qtype) { | |||
case Q_HELP: | |||
printf(qhelp_docstring); | |||
printf(qhelp_docstring,"\n"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good find. But here qhelp_docstring
works as a format specifier (the same as printf("Hello world");
). So to do it proper, it could be rewritten as:
printf("%s\n", qhelp_docstring);
@@ -1,4 +1,6 @@ | |||
#include "simpledb.h" | |||
#ifndef __SIMPLEDB_H__ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Include guards are usually not required given that you work with modern compiler.
For more, see #1 (comment)
simpledb.c
Outdated
@@ -10,6 +12,8 @@ | |||
#include <string.h> | |||
#include <errno.h> | |||
|
|||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a good reason for 2 extra newlines. Before committing, it's better to see git diff
@@ -18,7 +22,7 @@ enum err item_read_f(FILE *fp, struct dbitem *item) | |||
uint8_t buffer[sizeof(*item) + HASH_SIZE]; | |||
if (sizeof(buffer) != fread(buffer, 1, sizeof(buffer), fp)) | |||
return E_FREAD; | |||
uLong crc_file = *(uLong *)buffer; | |||
uLong crc_file = *(uLong *)buffer; /* endianness-independency for zlib */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good find! But <tab>
is 8 spaces, not 4 (as required by CodingStyle)
simpledb.h
Outdated
@@ -1,13 +1,14 @@ | |||
#include <limits.h> | |||
#include <stdio.h> | |||
|
|||
#define SIMPLEDB_H |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
useless stuff here
simpledb.h
Outdated
@@ -1,13 +1,14 @@ | |||
#include <limits.h> | |||
#include <stdio.h> | |||
|
|||
#define SIMPLEDB_H | |||
#ifdef DEBUG | |||
#define dbg(X, ...) do { \ | |||
fprintf(stderr, ("LOG> " X "\n"), ## __VA_ARGS__); \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It will be good to allow this macro to return value, i.e.
#define dbg(X, ...) ({int __ret = fprintf(stderr, ("LOG> " X "\n"), ## __VA_ARGS__); __ret;})
But it relies on GCC extensions. See this link for more
Thanks for your comments! I make the appropriate changes to my branch of the project. Please consider them. |
Changes to the training project.