diff --git a/Makefile b/Makefile index 81961ce1bb..d6efed7069 100644 --- a/Makefile +++ b/Makefile @@ -24,7 +24,7 @@ libsass: libsass_objs prelexer.o libsass_objs: sass_interface.cpp $(CPP_FILES) - g++ -O2 -c -combine sass_interface.cpp $(CPP_FILES) + g++ -O2 -Wall -c -combine sass_interface.cpp $(CPP_FILES) clean: rm -rf *.o *.a \ No newline at end of file diff --git a/document.cpp b/document.cpp index 9faec2aa07..e0138df8bc 100644 --- a/document.cpp +++ b/document.cpp @@ -139,9 +139,11 @@ namespace Sass { case expanded: root.emit_expanded_css(output, ""); break; + default: + break; } string retval(output.str()); if (!retval.empty()) retval.resize(retval.size()-1); return retval; } -} \ No newline at end of file +} diff --git a/document_parser.cpp b/document_parser.cpp index 2d987dd703..13de0553af 100644 --- a/document_parser.cpp +++ b/document_parser.cpp @@ -85,6 +85,8 @@ namespace Sass { catch (string& path) { read_error("error reading file \"" + path + "\""); } + // unreached statement + return Node(Node::none); } Node Document::parse_mixin_definition() @@ -370,10 +372,9 @@ namespace Sass { else if (peek< exactly<'['> >(position)) { return parse_attribute_selector(); } - else { - syntax_error("invalid selector after " + lexed.to_string()); - } - } + syntax_error("invalid selector after " + lexed.to_string()); + // unreached statement + return Node(Node::none);} Node Document::parse_pseudo() { if (lex< pseudo_not >()) { @@ -420,9 +421,9 @@ namespace Sass { else if (lex < sequence< pseudo_prefix, identifier > >()) { return Node(Node::pseudo, line_number, lexed); } - else { - syntax_error("unrecognized pseudo-class or pseudo-element"); - } + syntax_error("unrecognized pseudo-class or pseudo-element"); + // unreached statement + return Node(Node::none); } Node Document::parse_attribute_selector() @@ -477,7 +478,7 @@ namespace Sass { block.has_statements = true; } else { - for (int i = 0; i < imported_tree.size(); ++i) { + for (size_t i = 0; i < imported_tree.size(); ++i) { if (imported_tree[i].type == Node::comment || imported_tree[i].type == Node::rule) { block[0].has_statements = true; @@ -512,7 +513,7 @@ namespace Sass { // block << parse_ruleset(); // block.has_blocks = true; // } - else if (const char* p = lookahead_for_selector(position)) { + else if (lookahead_for_selector(position)) { block << parse_ruleset(definition); block[0].has_blocks = true; } @@ -834,6 +835,8 @@ namespace Sass { } syntax_error("error reading values after " + lexed.to_string()); + // unreached statement + return Node(Node::none); } extern const char hash_lbrace[] = "#{"; @@ -852,7 +855,8 @@ namespace Sass { Node schema(Node::string_schema, context.registry, line_number, 1); while (i < str.end) { - if (p = find_first_in_interval< sequence< negate< exactly<'\\'> >, exactly > >(i, str.end)) { + p = find_first_in_interval< sequence< negate< exactly<'\\'> >, exactly > >(i, str.end); + if (p) { if (i < p) schema << Node(Node::identifier, line_number, Token::make(i, p)); // accumulate the preceding segment if it's nonempty const char* j = find_first_in_interval< exactly >(p, str.end); // find the closing brace if (j) { @@ -1122,4 +1126,4 @@ namespace Sass { // // return p; // } -// } \ No newline at end of file +// } diff --git a/eval_apply.cpp b/eval_apply.cpp index 6b531e0634..8a09e3bc43 100644 --- a/eval_apply.cpp +++ b/eval_apply.cpp @@ -142,6 +142,9 @@ namespace Sass { case Node::gte: return (lhs >= rhs) ? T : F; case Node::lt: return (lhs < rhs) ? T : F; case Node::lte: return (lhs <= rhs) ? T : F; + default: + eval_error("unknown comparison operator " + expr.content.token.to_string(), expr.line_number, expr.file_name); + return Node(Node::none); } } break; @@ -150,7 +153,7 @@ namespace Sass { acc << eval(expr[0], env, f_env, registry); Node rhs(eval(expr[2], env, f_env, registry)); accumulate(expr[1].type, acc, rhs, registry); - for (int i = 3; i < expr.size(); i += 2) { + for (size_t i = 3; i < expr.size(); i += 2) { Node rhs(eval(expr[i+1], env, f_env, registry)); accumulate(expr[i].type, acc, rhs, registry); } @@ -163,7 +166,7 @@ namespace Sass { acc << eval(expr[0], env, f_env, registry); Node rhs(eval(expr[2], env, f_env, registry)); accumulate(expr[1].type, acc, rhs, registry); - for (int i = 3; i < expr.size(); i += 2) { + for (size_t i = 3; i < expr.size(); i += 2) { Node rhs(eval(expr[i+1], env, f_env, registry)); accumulate(expr[i].type, acc, rhs, registry); } @@ -248,7 +251,7 @@ namespace Sass { case Node::string_schema: case Node::value_schema: { // cerr << "evaluating schema of size " << expr.size() << endl; - for (int i = 0; i < expr.size(); ++i) { + for (size_t i = 0; i < expr.size(); ++i) { expr[i] = eval(expr[i], env, f_env, registry); } return expr; @@ -258,6 +261,8 @@ namespace Sass { return expr; } } + + return expr; } Node accumulate(Node::Type op, Node& acc, Node& rhs, vector*>& registry) @@ -400,7 +405,7 @@ namespace Sass { } } // plug the holes with default arguments if any - for (int i = 0; i < params.size(); ++i) { + for (size_t i = 0; i < params.size(); ++i) { if (params[i].type == Node::assignment) { Node param(params[i]); Token name(param[0].content.token); @@ -411,7 +416,7 @@ namespace Sass { } // lexically link the new environment and eval the mixin's body bindings.link(env.global ? *env.global : env); - for (int i = 0; i < body.size(); ++i) { + for (size_t i = 0; i < body.size(); ++i) { body[i] = eval(body[i], bindings, f_env, registry); } return body; diff --git a/functions.cpp b/functions.cpp index 23059be0e8..f4b6b241b6 100644 --- a/functions.cpp +++ b/functions.cpp @@ -568,12 +568,11 @@ namespace Sass { else if (!n1.is_numeric() && !n2.is_numeric()) { eval_error("arguments to comparable must be numeric", n1.line_number, n1.file_name); } - else { - Node F(Node::boolean); - F.line_number = n1.line_number; - F.content.boolean_value = false; - return F; - } + + Node F(Node::boolean); + F.line_number = n1.line_number; + F.content.boolean_value = false; + return F; } // Boolean Functions /////////////////////////////////////////////////// @@ -597,4 +596,4 @@ namespace Sass { } -} \ No newline at end of file +} diff --git a/node.cpp b/node.cpp index 3d635e452d..381710a165 100644 --- a/node.cpp +++ b/node.cpp @@ -60,11 +60,9 @@ namespace Sass { // result += at(0).to_string(t == backref ? prefix : ""); // } - Node::Type t = at(0).type; result += at(0).to_string(at(0).has_backref ? prefix : ""); for (size_t i = 1; i < size(); ++i) { - Node::Type t = at(i).type; result += " "; result += at(i).to_string(at(i).has_backref ? prefix : ""); } @@ -395,6 +393,8 @@ namespace Sass { case value: buf << ' ' << string(content.token); break; + default: + break; } } diff --git a/prelexer.hpp b/prelexer.hpp index 73b878f84a..c2f78dc6a0 100644 --- a/prelexer.hpp +++ b/prelexer.hpp @@ -388,8 +388,8 @@ namespace Sass { template const char* find_first_in_interval(const char* beg, const char* end) { while ((beg < end) && *beg) { - const char* p; - if (p = mx(beg)) return p; + const char* p = mx(beg); + if (p) return p; ++beg; } return 0; diff --git a/sass_interface.cpp b/sass_interface.cpp index 890a1866ba..8ad6166593 100644 --- a/sass_interface.cpp +++ b/sass_interface.cpp @@ -13,26 +13,28 @@ extern "C" { using namespace std; sass_context* sass_new_context() - { return (sass_context*) malloc(sizeof(sass_context)); } + { return (sass_context*) calloc(1, sizeof(sass_context)); } void sass_free_context(sass_context* ctx) { - free(ctx->output_string); + if (ctx->output_string) + free(ctx->output_string); free(ctx); } sass_file_context* sass_new_file_context() - { return (sass_file_context*) malloc(sizeof(sass_file_context)); } + { return (sass_file_context*) calloc(1, sizeof(sass_file_context)); } void sass_free_file_context(sass_file_context* ctx) { - free(ctx->output_string); + if (ctx->output_string) + free(ctx->output_string); free(ctx); } sass_folder_context* sass_new_folder_context() - { return (sass_folder_context*) malloc(sizeof(sass_folder_context)); } - + { return (sass_folder_context*) calloc(1, sizeof(sass_folder_context)); } + static char* process_document(Sass::Document& doc, int style) { using namespace Sass;