antirez / antirez/sds

Unexpected behaviour

オープン
#145 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る
主要言語
C
スター
5.6k
フォーク
510
PR マージ指標
30日以内にマージされた PR はありません

説明

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

コントリビューションガイド

このリポジトリのコントリビューションガイドは索引されていません

評価

この issue はまだ評価されていません。

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。