10 Commits

Author SHA1 Message Date
Lukas Fleischer
2702a61b0e Fix hash table issues with ISO C99
ISO C99 forbids unnamed structs/unions and nested functions. Move the
"HTABLE_HEAD" and "HTABLE_GENERATE" parts out of the function body and
place them at the very top of the file (where function definitions are
allowed). Also, remove the unnamed struct from "htable.h" (which was
useless anyway).

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2012-02-19 03:08:16 +01:00
Lukas Fleischer
c17b535a33 Fix up strncat() usage
The last argument to strncat() should not be the total buffer length; it
should be the space remaining:

    The strncat() function shall append not more than n bytes (a null
    byte and bytes that follow it are not appended) from the array
    pointed to by s2 to the end of the string pointed to by s1. The
    initial byte of s2 overwrites the null byte at the end of s1. A
    terminating null byte is always appended to the result.

This patch fixes a couple of potential buffer overflow vulnerabilities.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2012-02-18 16:00:18 +01:00
Lukas Fleischer
a79a33e8f4 Split note file generation into separate function
We currently use this in one place only but might reuse this a couple of
times later (when migrating to libical).

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2012-01-17 00:52:39 +01:00
Lukas Fleischer
7cc6305588 Do not cast unused return values to void
A small style fix that removes all remaining "(void)" casts. Using these
isn't encouraged in GNU coding guidelines and doesn't serve a certain
purpose, except for satisfying a few static code analysis tools. We
already nuked some of these in previous patches, but this semantic patch
should fix what's left:

    @@
    identifier func;
    @@

    - (void)func (
    + func (
    ...);

Long lines were re-formatted manually.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2011-11-02 18:32:17 +01:00
Lukas Fleischer
8d71923d4f Add a garbage collector for note files
Now that we use hashes to identify notes, a garbage collector comes in
handy. We search for note files that aren't referenced anywhere. Such
files might come up if a note, that isn't connected with any other item,
is edited.

Huge parts of this code are very hackish due to our data structure
layout and the way our hash table implementation works.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2011-10-05 12:25:47 +02:00
Lukas Fleischer
6c7edfbb86 Do not unlink() note files on note removal
Now that we use hash-based note file names, note files should never be
unlinked as a note file might be shared.

Also, remove the ERASE_FORCE_KEEP_NOTE flag that no longer makes any
sense.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2011-10-05 12:25:47 +02:00
Lukas Fleischer
5c6a00ee93 Use hash-bashed file names in edit_note()
Note file names are now generated based on their content. Items using
the same note will share a single note file.

Please note that this implies a few changes:

* Both random-style and hash-style note files need to be handled to
  ensure we do not break backwards compatibility.

* Note files may not be moved or deleted if a note is changed or removed
  since the original note file might be used by another item as well.

* A garbage collector to remove unreferenced note files needs to be
  implemented.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2011-10-05 12:25:47 +02:00
Lukas Fleischer
2fe7a36aab Accept variable length note names
Read up to the first blank in note_read() instead of assuming a
fixed-width note file name. Accept everything up to 40 characters (which
is the length of a SHA1 hash in hexadecimal representation).

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2011-10-05 12:25:47 +02:00
Lukas Fleischer
bc97d60ef2 Refactor out note deserialization
Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2011-10-05 12:25:47 +02:00
Lukas Fleischer
87664095cd Refactor out note functions
* Add new note_edit() and note_view() helper functions. Use these
  instead of copy-pasted code in *_note_edit().

* Move all note-related functions (note_edit(), note_view(),
  note_erase()) to a new source file "note.c".

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
2011-07-21 18:13:40 +02:00