Unexpected behaviour
- Lingua principale
- C
- Stelle
- 5.6k
- Fork
- 510
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Descrizione
Hi Salvatore,
I came across some unexpected behaviour while using the sdsMakeRoomFor() and sdsrange() functions. Please have a look below.
PS: It might be my one misuse of the library, but curious to hear what you think.
>$ echo "test" >> test_file.txt
```C
#include
#include "sds/sds.h"
#define BUFSIZE 4096
static void expected_behaviour(FILE* const f) {
sds s = sdsnew("abc");
s = sdsMakeRoomFor(s, BUFSIZE);
while (fgets(s, BUFSIZE, f)) {
sdsrange(s, 0, 2);
printf("%s", s); // prints: tes
}
printf("\n");
sdsfree(s);
}
static void unexpected_behaviour(FILE* const f) {
// Can sdsempty() be used here?
sds s = sdsMakeRoomFor(sdsempty(), BUFSIZE);
while (fgets(s, BUFSIZE, f)) {
// Why isn't sdsrange() working as expected?
sdsrange(s, 0, 2);
printf("%s", s); // prints: test\n
}
printf("\n");
sdsfree(s);
}
int main(void) {
FILE* const f = fopen("test_file.txt", "r"); // assume valid file
expected_behaviour(f);
fseek(f, 0, SEEK_SET);
unexpected_behaviour(f);
fclose(f)
return 0;
}
```
Guida per i contributori
Nessuna guida per i contributori indicizzata per questo repository
Valutazione
Questa issue non è ancora stata valutata.