Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

Buffer full when inserting latter value of pair to the map

オープン
#190 コメント 4 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
25/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
停滞
技術スタック
c

調査の方向性

Issue に示されている cbor_encoder_create_map と cbor_encode_byte_string の呼び出しから始め、その後、バッファー満杯エラーが encoder の状態にどのような影響を与えるかを調べてください。値のエンコードに失敗した場合に、対応する値のないキーが map に残るかどうかを確認し、静的に割り当てられたバッファーでサポートされている復旧手順を文書化またはテストしてください。

索引モデルが issue の本文から書いたものです。

説明

Hi!

I have a question which I have not found answer for. Since map contains pairs of items and I understood basically as dictionary (albeit basically same key could occur there multiple times but in my use case not), first value being a key and second one being a value.

So something like:

uint8_t payload[BUFFER_SIZE];
CborEncoder encoder, mapEncoder;
cbor_encoder_init(&encoder, payload, BUFFER_SIZE, 0);
cbor_encoder_create_map(&encoder, &mapEncoder, CborIndefiniteLength); // Don't know in advance how many
...
// Key value pairs are inserted
// until buffer is almost full
...
// Here, inserting key that still fits. Using uint key values for length optimization
// This one succeeds
cbor_encode_uint(&mapEncoder, 0xDEAD);
// Not matter what is the value but something that does not fit. For example string
CborError err = cbor_encode_byte_string(&mapEncoder, "whatever", 8);

What would be the correct procedure to take when writing a key fits to buffer but when writing the value, the buffer is exceeded? We have statically allocated buffer of specific size so it is not possible to reallocate more room.

Currently I'm now evaluating the size of the key+value beforehand and then evaluating whether whole key+value combination is inserted at all. Albeit it works, it feels bit ugly. Instead, if writing of the value fails, the key could be reverted as well (because otherwise when map is closed, last item contains only key and not value). I cannot find any means to do that though.

Any suggestions?

PS Otherwise, this works like a charm and fits to my use case perfectly.

主要言語
C
スター
634
フォーク
222
平均マージ
1日 25分
マージ済み PR(30日)
2

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

intel/tinycbor のほかの issue

intel/tinycbor の issue をすべて見る

似ている issue

C の issue をもっと見る

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

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