Skip to content
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

Even less warnings #13

Merged
merged 3 commits into from
Apr 27, 2012
Merged

Even less warnings #13

merged 3 commits into from
Apr 27, 2012

Conversation

larsimmisch
Copy link
Contributor

Two more patches, and then only one warning remains (and that should actually be taken care of properly)

The last patch, titled default statements and "control reaches end of non-void function" should be reviewed carefully. I've tried to do sensible things, but I was a bit on autopilot.

- more signed/unsigned
- unused variables
- suggest braces around assignment
One warning remains and should be taken care of properly.

In any case: this patch should be reviewed carefully.
@akhleung
Copy link

Wow, thanks for the cleanup! I'll review that last patch this evening.

malloc does not initialize the memory to zero, so

sass_context *ctx = sass_new_context()

will create a context with a random value in ctx->output_string.

If sass_free_context(ctx) was called immediately thereafter,
ctx->output_string would have a random value and the result of the
free(ctx->output_string) would be undefined.

In the worst case, this corrupts the heap and the process dies much much later.

Also, free isn't delete and mustn't be called with a NULL pointer.
@larsimmisch
Copy link
Contributor Author

You're welcome.

Do have a look at 8b24df9. That one is really a potential problem.

@larsimmisch
Copy link
Contributor Author

Also, may I suggest that the C-API is changed?

I'd do something like:

struct sass_context {
  const char *output_string;
  int error_status;
  const char* error_message;
};

// options may be NULL
int sass_compile(const char *input, struct sass_context *ctx, struct sass_options *options);

// sass_compile_file never sets the output_string in sass_context and writes to output instead
int sass_compile_file(FILE *input, FILE *output, struct sass_context *ctx, struct sass_options *options);

I would omit sass_compile_folder. It's a friendly idea, but if there is an error, there is no way to signal where the error occurs.

Also, for the record: Yes, this isn't pretty, even uglier than the current version. But sass_context is only written to in this draft, which avoids a bit of confusion.

I think that sass_compile_file that outputs to a file would be nice, because on more memory constrained sustem (think Raspberry P)i, the result of he compilation might not fit into memory.

If you are interested, I can work on a patch.

akhleung pushed a commit that referenced this pull request Apr 27, 2012
@akhleung akhleung merged commit d7b1361 into sass:master Apr 27, 2012
@HamptonMakes
Copy link
Member

lars- yeah, I'm up for that change. I like it.

Just have to make sure to coordinate this with the SassJS guys' work.

Or, were you helping with that too?

@larsimmisch
Copy link
Contributor Author

No, I just helped out with the Python wrappers.

I'll be offline for a week now, but when I'm back, I'll try to come up with a patch and look at what the SassJS guys are up to.

@HamptonMakes
Copy link
Member

Lars, I noticed you said there were no tests... there are! They are just in SassC... which is the
recommended way to dev on libsass.

I just added a note to the readme about this... 6b8405d

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants