Skip to content

Commit

Permalink
Replace final with fin to make clang-format-3.9 happy
Browse files Browse the repository at this point in the history
  • Loading branch information
tatsuhiro-t committed Oct 15, 2016
1 parent a591001 commit bc0f501
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 25 deletions.
20 changes: 10 additions & 10 deletions lib/nghttp2_hd.c
Expand Up @@ -828,28 +828,28 @@ static size_t encode_length(uint8_t *buf, size_t n, size_t prefix) {
* If the |initial| is nonzero, it is used as a initial value, this
* function assumes the |in| starts with intermediate data.
*
* An entire integer is decoded successfully, decoded, the |*final| is
* An entire integer is decoded successfully, decoded, the |*fin| is
* set to nonzero.
*
* This function stores the decoded integer in |*res| if it succeed,
* including partial decoding (in this case, number of shift to make
* in the next call will be stored in |*shift_ptr|) and returns number
* of bytes processed, or returns -1, indicating decoding error.
*/
static ssize_t decode_length(uint32_t *res, size_t *shift_ptr, int *final,
static ssize_t decode_length(uint32_t *res, size_t *shift_ptr, int *fin,
uint32_t initial, size_t shift, const uint8_t *in,
const uint8_t *last, size_t prefix) {
uint32_t k = (uint8_t)((1 << prefix) - 1);
uint32_t n = initial;
const uint8_t *start = in;

*shift_ptr = 0;
*final = 0;
*fin = 0;

if (n == 0) {
if ((*in & k) != k) {
*res = (*in) & k;
*final = 1;
*fin = 1;
return 1;
}

Expand Down Expand Up @@ -891,7 +891,7 @@ static ssize_t decode_length(uint32_t *res, size_t *shift_ptr, int *final,
}

*res = n;
*final = 1;
*fin = 1;
return (ssize_t)(in + 1 - start);
}

Expand Down Expand Up @@ -1665,13 +1665,13 @@ static ssize_t hd_inflate_read_huff(nghttp2_hd_inflater *inflater,
nghttp2_buf *buf, const uint8_t *in,
const uint8_t *last) {
ssize_t readlen;
int final = 0;
int fin = 0;
if ((size_t)(last - in) >= inflater->left) {
last = in + inflater->left;
final = 1;
fin = 1;
}
readlen = nghttp2_hd_huff_decode(&inflater->huff_decode_ctx, buf, in,
(size_t)(last - in), final);
(size_t)(last - in), fin);

if (readlen < 0) {
DEBUGF("inflatehd: huffman decoding failed\n");
Expand Down Expand Up @@ -2269,10 +2269,10 @@ int nghttp2_hd_emit_table_size(nghttp2_bufs *bufs, size_t table_size) {
return emit_table_size(bufs, table_size);
}

ssize_t nghttp2_hd_decode_length(uint32_t *res, size_t *shift_ptr, int *final,
ssize_t nghttp2_hd_decode_length(uint32_t *res, size_t *shift_ptr, int *fin,
uint32_t initial, size_t shift, uint8_t *in,
uint8_t *last, size_t prefix) {
return decode_length(res, shift_ptr, final, initial, shift, in, last, prefix);
return decode_length(res, shift_ptr, fin, initial, shift, in, last, prefix);
}

static size_t hd_get_num_table_entries(nghttp2_hd_context *context) {
Expand Down
8 changes: 4 additions & 4 deletions lib/nghttp2_hd.h
Expand Up @@ -372,7 +372,7 @@ int nghttp2_hd_emit_table_size(nghttp2_bufs *bufs, size_t table_size);
nghttp2_hd_nv nghttp2_hd_table_get(nghttp2_hd_context *context, size_t index);

/* For unittesting purpose */
ssize_t nghttp2_hd_decode_length(uint32_t *res, size_t *shift_ptr, int *final,
ssize_t nghttp2_hd_decode_length(uint32_t *res, size_t *shift_ptr, int *fin,
uint32_t initial, size_t shift, uint8_t *in,
uint8_t *last, size_t prefix);

Expand Down Expand Up @@ -410,8 +410,8 @@ void nghttp2_hd_huff_decode_context_init(nghttp2_hd_huff_decode_context *ctx);
* will be written to |buf|. This function assumes that |buf| has the
* enough room to store the decoded byte string.
*
* The caller must set the |final| to nonzero if the given input is
* the final block.
* The caller must set the |fin| to nonzero if the given input is the
* final block.
*
* This function returns the number of read bytes from the |in|.
*
Expand All @@ -425,6 +425,6 @@ void nghttp2_hd_huff_decode_context_init(nghttp2_hd_huff_decode_context *ctx);
*/
ssize_t nghttp2_hd_huff_decode(nghttp2_hd_huff_decode_context *ctx,
nghttp2_buf *buf, const uint8_t *src,
size_t srclen, int final);
size_t srclen, int fin);

#endif /* NGHTTP2_HD_H */
16 changes: 8 additions & 8 deletions tests/nghttp2_hd_test.c
Expand Up @@ -1433,7 +1433,7 @@ static size_t encode_length(uint8_t *buf, uint64_t n, size_t prefix) {
void test_nghttp2_hd_decode_length(void) {
uint32_t out;
size_t shift;
int final;
int fin;
uint8_t buf[16];
uint8_t *bufp;
size_t len;
Expand All @@ -1443,39 +1443,39 @@ void test_nghttp2_hd_decode_length(void) {
memset(buf, 0, sizeof(buf));
len = encode_length(buf, UINT32_MAX, 7);

rv = nghttp2_hd_decode_length(&out, &shift, &final, 0, 0, buf, buf + len, 7);
rv = nghttp2_hd_decode_length(&out, &shift, &fin, 0, 0, buf, buf + len, 7);

CU_ASSERT((ssize_t)len == rv);
CU_ASSERT(0 != final);
CU_ASSERT(0 != fin);
CU_ASSERT(UINT32_MAX == out);

/* Make sure that we can decode integer if we feed 1 byte at a
time */
out = 0;
shift = 0;
final = 0;
fin = 0;
bufp = buf;

for (i = 0; i < len; ++i, ++bufp) {
rv = nghttp2_hd_decode_length(&out, &shift, &final, out, shift, bufp,
rv = nghttp2_hd_decode_length(&out, &shift, &fin, out, shift, bufp,
bufp + 1, 7);

CU_ASSERT(rv == 1);

if (final) {
if (fin) {
break;
}
}

CU_ASSERT(i == len - 1);
CU_ASSERT(0 != final);
CU_ASSERT(0 != fin);
CU_ASSERT(UINT32_MAX == out);

/* Check overflow case */
memset(buf, 0, sizeof(buf));
len = encode_length(buf, 1ll << 32, 7);

rv = nghttp2_hd_decode_length(&out, &shift, &final, 0, 0, buf, buf + len, 7);
rv = nghttp2_hd_decode_length(&out, &shift, &fin, 0, 0, buf, buf + len, 7);

CU_ASSERT(-1 == rv);
}
Expand Down
6 changes: 3 additions & 3 deletions tests/nghttp2_test_helper.c
Expand Up @@ -158,14 +158,14 @@ ssize_t inflate_hd(nghttp2_hd_inflater *inflater, nva_out *out,
nghttp2_buf_chain *ci;
nghttp2_buf *buf;
nghttp2_buf bp;
int final;
int fin;
size_t processed;

processed = 0;

for (ci = bufs->head; ci; ci = ci->next) {
buf = &ci->buf;
final = nghttp2_buf_len(buf) == 0 || ci->next == NULL;
fin = nghttp2_buf_len(buf) == 0 || ci->next == NULL;
bp = *buf;

if (offset) {
Expand All @@ -179,7 +179,7 @@ ssize_t inflate_hd(nghttp2_hd_inflater *inflater, nva_out *out,
for (;;) {
inflate_flags = 0;
rv = nghttp2_hd_inflate_hd2(inflater, &nv, &inflate_flags, bp.pos,
nghttp2_buf_len(&bp), final);
nghttp2_buf_len(&bp), fin);

if (rv < 0) {
return rv;
Expand Down

0 comments on commit bc0f501

Please sign in to comment.