Unexpected behaviour
- Lenguaje dominante
- C
- Estrellas
- 5.6k
- Forks
- 510
- Métricas de merge de PR
- Sin PR fusionados en 30 d
Descripción
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;
}
```
Guía de contribución
No hay ninguna guía de contribución indexada para este repositorio
Evaluación
Este issue todavía no se ha evaluado.