antirez / antirez/sds

Unexpected behaviour

Đang mở
#145 1 bình luận 0 reaction 0 người được giao Xem trên GitHub
Ngôn ngữ chính
C
Star
5.6k
Fork
510
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

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;
}
```

Hướng dẫn đóng góp

Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.