Hot answers tagged

10 votes

Toggle 2 LEDs using a timer XMEGA-A3BU Xplained

The optimizer has a habit of optimizing out my timing loops. This is (a) a non-surprise, and (b) somewhat of a red flag when it comes to coding practice. If you're writing timing loops that attempt ...
user avatar
  • 47.8k
7 votes

Toggle 2 LEDs using a timer XMEGA-A3BU Xplained

Portable Register Addressing to allow the code using this file to port to other devices. I seriously doubt that. Other devices may have (and will have) completely different mapping. What's worse, the ...
user avatar
  • 52.9k
6 votes
Accepted

Arbitrary Length Input in C

End-of-file When nothing is read, code returns an allocated "". That is indistinguishable from reading only a '\n' as ...
user avatar
5 votes

CSV to TSV converter in C+yacc+lex and a Makefile

Overview Code Review Starting at the bottom and working up: Lexer This looks like it should work. The only thing I would do differently is the . match at the end. ...
user avatar
  • 91.5k
4 votes

Toggle 2 LEDs using a timer XMEGA-A3BU Xplained

Use a standard library It looks like you have written a lot of code to deal with AVR registers. Maybe it was required that you wrote everything from scratch, but it would be much better if you could ...
user avatar
  • 32.3k
3 votes

tee: copy standard input to both stdout and a file

Disclaimer: My C is a little rusty, as I don't write it regularly. Your code is clear and straightforward and I'm happy with your variable names (which is not always the case), but there are some ...
user avatar
  • 1,192
3 votes

Convert from decimal to binary and octal

The global variables make it harder to reuse your code. They seem to be unnecessary anyway: the integer variables are used only in main(), and ...
user avatar
  • 57.6k
3 votes
Accepted

Simple tokenizer in C

Apparent uniform formatting - good Hope OP is using an auto-formatter. Bug? mem_free(rv) is suspicious. Is a free needed on successful re-allocation? ...
user avatar
3 votes
Accepted

Stack implementation in C programming Language

Advice 1 time.h is not used. Remove it. Same for string.h. Advice 2 ...
user avatar
  • 25.3k
2 votes

change file attributes on a Linux file system with chattr

General Overview The code is fairly well written and a good start. I'm sorry but I can't help out on the POSIX part of the question. Possible Bug The current parsing of the command line has been over ...
user avatar
  • 18.1k
2 votes

CSV to TSV converter in C+yacc+lex and a Makefile

Makefile The Makefile looks generally good. We shouldn't need to write a .c.o rule - the built-in one is likely better. I recommend adding some suitable warning/...
user avatar
  • 57.6k
2 votes
Accepted

C lang CGI form/string handle

Some bugs: malloc() can fail. When it does, it returns a null pointer, which we must not use as destination for strcpy(). The ...
user avatar
  • 57.6k
2 votes

Convert from decimal to binary and octal

The code presented could be more readable. Starting with comments telling what "everything" is there for. Naming: integers/numbers are not decimal. Representations are, unless specified ...
user avatar
  • 4,283
2 votes

tee: copy standard input to both stdout and a file

I'm going to mostly take one part of the code to make some points, but it applies throughout. I have to say that I dislike side effects on the right of logical expressions. Whilst I appreciate that ...
user avatar
2 votes

tee: copy standard input to both stdout and a file

sizeof (what) read(0, buf, sizeof(buf)) is a nice way to determine the size of buf. Code used the size of the object. Better to ...
user avatar
2 votes

another attempt to implement the tee command

I see no reason to use system calls. Here it on;y hurts portability. After all, a conforming implementation is not required to provide open, read, write, etc. ...
user avatar
  • 52.9k
2 votes

display processes children

Limit the responsibilites of createChild() The function createChild() does many things; it resizes an array, forks a new process,...
user avatar
  • 32.3k
1 vote

Longest Increasing Subsequence of Rectangles

General Observations Overall a well structure program, but it could be more readable. The program is not completely portable since it uses variable array size and older versions of C or versions of C ...
user avatar
  • 18.1k
1 vote

Case-insensitive sort in C

Bug: String handling is unsigned For all functions in this subclause, each character shall be interpreted as if it had the type unsigned char (and therefore every possible object representation is ...
user avatar
1 vote
Accepted

OAuth implementation for Puredata

Almost certainly, Coverity is simply looking for all uses of strcat, strcpy, sprintf, etc., ...
user avatar
1 vote

change file attributes on a Linux file system with chattr

Sentinels on troublesome output When open fails, something is wrong. Sometimes a formed filename is amiss. Using sentinels like "\"%s\"" helps ...
user avatar
1 vote

Slice function for C

We're missing the necessary #include lines for malloc(), exit(), ...
user avatar
  • 57.6k
1 vote

n an array of N elements calculate its mean and count the number sub array of N-2 elements that have same mean

The single-letter variable names make the code hard to read. Use more informative names to help readers understand what your code is doing. Always assume input is erroneous or even hostile - never ...
user avatar
  • 57.6k
1 vote
Accepted

AES implementation in C

There's a lot of stuff in the header file that looks like implementation detail, which could be private to aes.c. The header should just have the public types and ...
user avatar
  • 57.6k

Only top scored, non community-wiki answers of a minimum length are eligible