Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
ccan
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
mirror
ccan
Commits
c16c0217
Commit
c16c0217
authored
Mar 22, 2021
by
Christopher McGeorge
Committed by
Rusty Russell
Sep 08, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix "for loop initial declarations are only allowed in C99 mode" compile errors.
parent
9fdfa56e
Changes
10
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
70 additions
and
39 deletions
+70
-39
ccan/crc32c/crc32c.c
ccan/crc32c/crc32c.c
+17
-10
ccan/crypto/xtea/xtea.c
ccan/crypto/xtea/xtea.c
+4
-2
ccan/edit_distance/edit_distance_dl.c
ccan/edit_distance/edit_distance_dl.c
+12
-8
ccan/edit_distance/edit_distance_lcs.c
ccan/edit_distance/edit_distance_lcs.c
+5
-3
ccan/edit_distance/edit_distance_lev.c
ccan/edit_distance/edit_distance_lev.c
+5
-3
ccan/edit_distance/edit_distance_rdl.c
ccan/edit_distance/edit_distance_rdl.c
+5
-3
ccan/io/poll.c
ccan/io/poll.c
+12
-4
ccan/json_escape/json_escape.c
ccan/json_escape/json_escape.c
+2
-1
ccan/pipecmd/pipecmd.c
ccan/pipecmd/pipecmd.c
+6
-4
ccan/str/base32/base32.c
ccan/str/base32/base32.c
+2
-1
No files found.
ccan/crc32c/crc32c.c
View file @
c16c0217
...
...
@@ -72,7 +72,8 @@ static inline uint32_t gf2_matrix_times(uint32_t *mat, uint32_t vec) {
/* Multiply a matrix by itself over GF(2). Both mat and square must have 32
rows. */
static
inline
void
gf2_matrix_square
(
uint32_t
*
square
,
uint32_t
*
mat
)
{
for
(
unsigned
n
=
0
;
n
<
32
;
n
++
)
unsigned
n
;
for
(
n
=
0
;
n
<
32
;
n
++
)
square
[
n
]
=
gf2_matrix_times
(
mat
,
mat
[
n
]);
}
...
...
@@ -87,7 +88,8 @@ static void crc32c_zeros_op(uint32_t *even, size_t len) {
/* put operator for one zero bit in odd */
odd
[
0
]
=
POLY
;
/* CRC-32C polynomial */
uint32_t
row
=
1
;
for
(
unsigned
n
=
1
;
n
<
32
;
n
++
)
{
unsigned
n
;
for
(
n
=
1
;
n
<
32
;
n
++
)
{
odd
[
n
]
=
row
;
row
<<=
1
;
}
...
...
@@ -111,7 +113,7 @@ static void crc32c_zeros_op(uint32_t *even, size_t len) {
}
while
(
len
);
/* answer ended up in odd -- copy to even */
for
(
unsigned
n
=
0
;
n
<
32
;
n
++
)
for
(
n
=
0
;
n
<
32
;
n
++
)
even
[
n
]
=
odd
[
n
];
}
...
...
@@ -121,7 +123,8 @@ static void crc32c_zeros(uint32_t zeros[][256], size_t len) {
uint32_t
op
[
32
];
crc32c_zeros_op
(
op
,
len
);
for
(
unsigned
n
=
0
;
n
<
256
;
n
++
)
{
unsigned
n
;
for
(
n
=
0
;
n
<
256
;
n
++
)
{
zeros
[
0
][
n
]
=
gf2_matrix_times
(
op
,
n
);
zeros
[
1
][
n
]
=
gf2_matrix_times
(
op
,
n
<<
8
);
zeros
[
2
][
n
]
=
gf2_matrix_times
(
op
,
n
<<
16
);
...
...
@@ -265,7 +268,8 @@ uint32_t crc32c(uint32_t crc, void const *buf, size_t len) {
static
bool
crc32c_once_little
;
static
uint32_t
crc32c_table_little
[
8
][
256
];
static
void
crc32c_init_sw_little
(
void
)
{
for
(
unsigned
n
=
0
;
n
<
256
;
n
++
)
{
unsigned
n
;
for
(
n
=
0
;
n
<
256
;
n
++
)
{
uint32_t
crc
=
n
;
crc
=
crc
&
1
?
(
crc
>>
1
)
^
POLY
:
crc
>>
1
;
crc
=
crc
&
1
?
(
crc
>>
1
)
^
POLY
:
crc
>>
1
;
...
...
@@ -277,9 +281,10 @@ static void crc32c_init_sw_little(void) {
crc
=
crc
&
1
?
(
crc
>>
1
)
^
POLY
:
crc
>>
1
;
crc32c_table_little
[
0
][
n
]
=
crc
;
}
for
(
unsigned
n
=
0
;
n
<
256
;
n
++
)
{
for
(
n
=
0
;
n
<
256
;
n
++
)
{
uint32_t
crc
=
crc32c_table_little
[
0
][
n
];
for
(
unsigned
k
=
1
;
k
<
8
;
k
++
)
{
unsigned
k
;
for
(
k
=
1
;
k
<
8
;
k
++
)
{
crc
=
crc32c_table_little
[
0
][
crc
&
0xff
]
^
(
crc
>>
8
);
crc32c_table_little
[
k
][
n
]
=
crc
;
}
...
...
@@ -340,7 +345,8 @@ static bool crc32c_once_big;
static
uint32_t
crc32c_table_big_byte
[
256
];
static
uint64_t
crc32c_table_big
[
8
][
256
];
static
void
crc32c_init_sw_big
(
void
)
{
for
(
unsigned
n
=
0
;
n
<
256
;
n
++
)
{
unsigned
n
;
for
(
n
=
0
;
n
<
256
;
n
++
)
{
uint32_t
crc
=
n
;
crc
=
crc
&
1
?
(
crc
>>
1
)
^
POLY
:
crc
>>
1
;
crc
=
crc
&
1
?
(
crc
>>
1
)
^
POLY
:
crc
>>
1
;
...
...
@@ -352,10 +358,11 @@ static void crc32c_init_sw_big(void) {
crc
=
crc
&
1
?
(
crc
>>
1
)
^
POLY
:
crc
>>
1
;
crc32c_table_big_byte
[
n
]
=
crc
;
}
for
(
unsigned
n
=
0
;
n
<
256
;
n
++
)
{
for
(
n
=
0
;
n
<
256
;
n
++
)
{
uint32_t
crc
=
crc32c_table_big_byte
[
n
];
crc32c_table_big
[
0
][
n
]
=
swap
(
crc
);
for
(
unsigned
k
=
1
;
k
<
8
;
k
++
)
{
unsigned
k
;
for
(
k
=
1
;
k
<
8
;
k
++
)
{
crc
=
crc32c_table_big_byte
[
crc
&
0xff
]
^
(
crc
>>
8
);
crc32c_table_big
[
k
][
n
]
=
swap
(
crc
);
}
...
...
ccan/crypto/xtea/xtea.c
View file @
c16c0217
...
...
@@ -11,8 +11,9 @@ uint64_t xtea_encipher(const struct xtea_secret *secret, uint64_t v)
{
const
uint32_t
delta
=
0x9E3779B9
;
uint32_t
v0
=
(
v
>>
32
),
v1
=
v
,
sum
=
0
;
int
i
;
for
(
i
nt
i
=
0
;
i
<
NUM_DOUBLE_ROUNDS
;
i
++
)
{
for
(
i
=
0
;
i
<
NUM_DOUBLE_ROUNDS
;
i
++
)
{
v0
+=
(((
v1
<<
4
)
^
(
v1
>>
5
))
+
v1
)
^
(
sum
+
secret
->
u
.
u32
[
sum
&
3
]);
sum
+=
delta
;
v1
+=
(((
v0
<<
4
)
^
(
v0
>>
5
))
+
v0
)
^
(
sum
+
secret
->
u
.
u32
[(
sum
>>
11
)
&
3
]);
...
...
@@ -24,8 +25,9 @@ uint64_t xtea_decipher(const struct xtea_secret *secret, uint64_t e)
{
const
uint32_t
delta
=
0x9E3779B9
;
uint32_t
v0
=
(
e
>>
32
),
v1
=
e
,
sum
=
delta
*
NUM_DOUBLE_ROUNDS
;
int
i
;
for
(
i
nt
i
=
0
;
i
<
NUM_DOUBLE_ROUNDS
;
i
++
)
{
for
(
i
=
0
;
i
<
NUM_DOUBLE_ROUNDS
;
i
++
)
{
v1
-=
(((
v0
<<
4
)
^
(
v0
>>
5
))
+
v0
)
^
(
sum
+
secret
->
u
.
u32
[(
sum
>>
11
)
&
3
]);
sum
-=
delta
;
v0
-=
(((
v1
<<
4
)
^
(
v1
>>
5
))
+
v1
)
^
(
sum
+
secret
->
u
.
u32
[
sum
&
3
]);
...
...
ccan/edit_distance/edit_distance_dl.c
View file @
c16c0217
...
...
@@ -41,10 +41,11 @@ ed_dist edit_distance_dl(const ed_elem *src, ed_size slen,
ed_dist
*
delcost
=
malloc
(
ED_TMAT_SIZE
(
slen
+
1
)
*
sizeof
(
ed_dist
));
ed_dist
*
delcostitr
=
delcost
;
ed_dist
*
delcostprevitr
=
delcost
;
ed_size
i2
,
i1
;
*
delcostitr
++
=
0
;
for
(
ed_size
i2
=
1
;
i2
<=
slen
;
++
i2
)
{
for
(
i2
=
1
;
i2
<=
slen
;
++
i2
)
{
ed_dist
costi2
=
ED_DEL_COST
(
src
[
i2
-
1
]);
for
(
ed_size
i1
=
0
;
i1
<
i2
;
++
i1
)
{
for
(
i1
=
0
;
i1
<
i2
;
++
i1
)
{
*
delcostitr
++
=
*
delcostprevitr
++
+
costi2
;
}
*
delcostitr
++
=
0
;
...
...
@@ -61,10 +62,11 @@ ed_dist edit_distance_dl(const ed_elem *src, ed_size slen,
ed_dist
*
inscost
=
malloc
(
ED_TMAT_SIZE
(
tlen
+
1
)
*
sizeof
(
ed_dist
));
ed_dist
*
inscostitr
=
inscost
;
ed_dist
*
inscostprevitr
=
inscost
;
ed_size
j2
,
j1
;
*
inscostitr
++
=
0
;
for
(
ed_size
j2
=
1
;
j2
<=
tlen
;
++
j2
)
{
for
(
j2
=
1
;
j2
<=
tlen
;
++
j2
)
{
ed_dist
costj2
=
ED_INS_COST
(
tgt
[
j2
-
1
]);
for
(
ed_size
j1
=
0
;
j1
<
j2
;
++
j1
)
{
for
(
j1
=
0
;
j1
<
j2
;
++
j1
)
{
*
inscostitr
++
=
*
inscostprevitr
++
+
costj2
;
}
*
inscostitr
++
=
0
;
...
...
@@ -73,7 +75,8 @@ ed_dist edit_distance_dl(const ed_elem *src, ed_size slen,
#endif
/* Initialize first row with maximal cost */
for
(
ed_size
i
=
0
;
i
<
slen
+
2
;
++
i
)
{
ed_size
i
,
j
;
for
(
i
=
0
;
i
<
slen
+
2
;
++
i
)
{
dist
[
i
]
=
maxdist
;
}
...
...
@@ -83,11 +86,11 @@ ed_dist edit_distance_dl(const ed_elem *src, ed_size slen,
/* Initialize row with cost to delete src[0..i-1] */
dist
[
-
1
]
=
maxdist
;
dist
[
0
]
=
0
;
for
(
ed_size
i
=
1
;
i
<=
slen
;
++
i
)
{
for
(
i
=
1
;
i
<=
slen
;
++
i
)
{
dist
[
i
]
=
dist
[
i
-
1
]
+
ED_DEL_COST
(
src
[
i
-
1
]);
}
for
(
ed_size
j
=
1
;
j
<=
tlen
;
++
j
)
{
for
(
j
=
1
;
j
<=
tlen
;
++
j
)
{
/* Largest y < i such that src[y] = tgt[j] */
ed_size
lastsrc
=
0
;
ed_dist
*
prevdist
=
dist
;
...
...
@@ -101,7 +104,8 @@ ed_dist edit_distance_dl(const ed_elem *src, ed_size slen,
* Loop invariant: lasttgt[ED_HASH_ELEM(c)] holds the largest
* x < j such that tgt[x-1] = c or 0 if no such x exists.
*/
for
(
ed_size
i
=
1
;
i
<=
slen
;
++
i
)
{
ed_size
i
;
for
(
i
=
1
;
i
<=
slen
;
++
i
)
{
ed_size
i1
=
lastsrc
;
ed_size
j1
=
lasttgt
[
ED_HASH_ELEM
(
src
[
i
-
1
])];
...
...
ccan/edit_distance/edit_distance_lcs.c
View file @
c16c0217
...
...
@@ -13,6 +13,8 @@
ed_dist
edit_distance_lcs
(
const
ed_elem
*
src
,
ed_size
slen
,
const
ed_elem
*
tgt
,
ed_size
tlen
)
{
ed_size
i
,
j
;
/* Optimization: Avoid malloc when row of distance matrix can fit on
* the stack.
*/
...
...
@@ -24,11 +26,11 @@ ed_dist edit_distance_lcs(const ed_elem *src, ed_size slen,
/* Initialize row with cost to delete src[0..i-1] */
dist
[
0
]
=
0
;
for
(
ed_size
i
=
1
;
i
<=
slen
;
++
i
)
{
for
(
i
=
1
;
i
<=
slen
;
++
i
)
{
dist
[
i
]
=
dist
[
i
-
1
]
+
ED_DEL_COST
(
src
[
i
-
1
]);
}
for
(
ed_size
j
=
1
;
j
<=
tlen
;
++
j
)
{
for
(
j
=
1
;
j
<=
tlen
;
++
j
)
{
/* Value for dist[j-1][i-1] (one row up, one col left). */
ed_dist
diagdist
=
dist
[
0
];
dist
[
0
]
=
dist
[
0
]
+
ED_INS_COST
(
tgt
[
j
-
1
]);
...
...
@@ -36,7 +38,7 @@ ed_dist edit_distance_lcs(const ed_elem *src, ed_size slen,
/* Loop invariant: dist[i] is the edit distance between first j
* elements of tgt and first i elements of src.
*/
for
(
ed_size
i
=
1
;
i
<=
slen
;
++
i
)
{
for
(
i
=
1
;
i
<=
slen
;
++
i
)
{
ed_dist
nextdiagdist
=
dist
[
i
];
if
(
ED_ELEM_EQUAL
(
src
[
i
-
1
],
tgt
[
j
-
1
]))
{
...
...
ccan/edit_distance/edit_distance_lev.c
View file @
c16c0217
...
...
@@ -13,6 +13,8 @@
ed_dist
edit_distance_lev
(
const
ed_elem
*
src
,
ed_size
slen
,
const
ed_elem
*
tgt
,
ed_size
tlen
)
{
ed_size
i
,
j
;
/* Optimization: Avoid malloc when row of distance matrix can fit on
* the stack.
*/
...
...
@@ -24,11 +26,11 @@ ed_dist edit_distance_lev(const ed_elem *src, ed_size slen,
/* Initialize row with cost to delete src[0..i-1] */
dist
[
0
]
=
0
;
for
(
ed_size
i
=
1
;
i
<=
slen
;
++
i
)
{
for
(
i
=
1
;
i
<=
slen
;
++
i
)
{
dist
[
i
]
=
dist
[
i
-
1
]
+
ED_DEL_COST
(
src
[
i
-
1
]);
}
for
(
ed_size
j
=
1
;
j
<=
tlen
;
++
j
)
{
for
(
j
=
1
;
j
<=
tlen
;
++
j
)
{
/* Value for dist[j-1][i-1] (one row up, one col left). */
ed_dist
diagdist
=
dist
[
0
];
dist
[
0
]
=
dist
[
0
]
+
ED_INS_COST
(
tgt
[
j
-
1
]);
...
...
@@ -36,7 +38,7 @@ ed_dist edit_distance_lev(const ed_elem *src, ed_size slen,
/* Loop invariant: dist[i] is the edit distance between first j
* elements of tgt and first i elements of src.
*/
for
(
ed_size
i
=
1
;
i
<=
slen
;
++
i
)
{
for
(
i
=
1
;
i
<=
slen
;
++
i
)
{
ed_dist
nextdiagdist
=
dist
[
i
];
if
(
ED_ELEM_EQUAL
(
src
[
i
-
1
],
tgt
[
j
-
1
]))
{
...
...
ccan/edit_distance/edit_distance_rdl.c
View file @
c16c0217
...
...
@@ -13,6 +13,8 @@
ed_dist
edit_distance_rdl
(
const
ed_elem
*
src
,
ed_size
slen
,
const
ed_elem
*
tgt
,
ed_size
tlen
)
{
ed_size
i
,
j
;
/* Optimization: Avoid malloc when required rows of distance matrix can
* fit on the stack.
*/
...
...
@@ -32,11 +34,11 @@ ed_dist edit_distance_rdl(const ed_elem *src, ed_size slen,
/* Initialize row with cost to delete src[0..i-1] */
dist
[
0
]
=
0
;
for
(
ed_size
i
=
1
;
i
<=
slen
;
++
i
)
{
for
(
i
=
1
;
i
<=
slen
;
++
i
)
{
dist
[
i
]
=
dist
[
i
-
1
]
+
ED_DEL_COST
(
src
[
i
-
1
]);
}
for
(
ed_size
j
=
1
;
j
<=
tlen
;
++
j
)
{
for
(
j
=
1
;
j
<=
tlen
;
++
j
)
{
/* Value for dist[j-2][i-1] (two rows up, one col left). */
/* Note: dist[0] is not initialized when j == 1, var unused. */
ed_dist
diagdist1
=
prevdist
[
0
];
...
...
@@ -51,7 +53,7 @@ ed_dist edit_distance_rdl(const ed_elem *src, ed_size slen,
/* Loop invariant: dist[i] is the edit distance between first j
* elements of tgt and first i elements of src.
*/
for
(
ed_size
i
=
1
;
i
<=
slen
;
++
i
)
{
for
(
i
=
1
;
i
<=
slen
;
++
i
)
{
ed_dist
nextdiagdist
=
dist
[
i
];
if
(
ED_ELEM_EQUAL
(
src
[
i
-
1
],
tgt
[
j
-
1
]))
{
...
...
ccan/io/poll.c
View file @
c16c0217
...
...
@@ -121,7 +121,9 @@ bool add_listener(struct io_listener *l)
static
int
find_always
(
const
struct
io_plan
*
plan
)
{
for
(
size_t
i
=
0
;
i
<
num_always
;
i
++
)
size_t
i
=
0
;
for
(
i
=
0
;
i
<
num_always
;
i
++
)
if
(
always
[
i
]
==
plan
)
return
i
;
return
-
1
;
...
...
@@ -287,8 +289,10 @@ static bool *exclusive(struct io_plan *plan)
/* For simplicity, we do one always at a time */
static
bool
handle_always
(
void
)
{
int
i
;
/* Backwards is simple easier to remove entries */
for
(
i
nt
i
=
num_always
-
1
;
i
>=
0
;
i
--
)
{
for
(
i
=
num_always
-
1
;
i
>=
0
;
i
--
)
{
struct
io_plan
*
plan
=
always
[
i
];
if
(
num_exclusive
&&
!*
exclusive
(
plan
))
...
...
@@ -323,10 +327,12 @@ bool backend_set_exclusive(struct io_plan *plan, bool excl)
* else that we manipulate events. */
static
void
exclude_pollfds
(
void
)
{
size_t
i
;
if
(
num_exclusive
==
0
)
return
;
for
(
size_t
i
=
0
;
i
<
num_fds
;
i
++
)
{
for
(
i
=
0
;
i
<
num_fds
;
i
++
)
{
struct
pollfd
*
pfd
=
&
pollfds
[
fds
[
i
]
->
backend_info
];
if
(
!
fds
[
i
]
->
exclusive
[
IO_IN
])
...
...
@@ -343,10 +349,12 @@ static void exclude_pollfds(void)
static
void
restore_pollfds
(
void
)
{
size_t
i
;
if
(
num_exclusive
==
0
)
return
;
for
(
size_t
i
=
0
;
i
<
num_fds
;
i
++
)
{
for
(
i
=
0
;
i
<
num_fds
;
i
++
)
{
struct
pollfd
*
pfd
=
&
pollfds
[
fds
[
i
]
->
backend_info
];
if
(
fds
[
i
]
->
listener
)
{
...
...
ccan/json_escape/json_escape.c
View file @
c16c0217
...
...
@@ -21,7 +21,8 @@ bool json_escape_eq(const struct json_escape *a, const struct json_escape *b)
bool
json_escape_needed
(
const
char
*
str
,
size_t
len
)
{
for
(
size_t
i
=
0
;
i
<
len
;
i
++
)
{
size_t
i
;
for
(
i
=
0
;
i
<
len
;
i
++
)
{
if
((
unsigned
)
str
[
i
]
<
' '
||
str
[
i
]
==
127
||
str
[
i
]
==
'"'
...
...
ccan/pipecmd/pipecmd.c
View file @
c16c0217
...
...
@@ -115,7 +115,8 @@ pid_t pipecmdarr(int *fd_tochild, int *fd_fromchild, int *fd_errfromchild,
goto
fail
;
if
(
childpid
==
0
)
{
for
(
int
i
=
0
;
i
<
num_child_close
;
i
++
)
int
i
;
for
(
i
=
0
;
i
<
num_child_close
;
i
++
)
close
(
child_close
[
i
]);
// Child runs command.
...
...
@@ -140,7 +141,7 @@ pid_t pipecmdarr(int *fd_tochild, int *fd_fromchild, int *fd_errfromchild,
/* Make (fairly!) sure all other fds are closed. */
int
max
=
sysconf
(
_SC_OPEN_MAX
);
for
(
i
nt
i
=
3
;
i
<
max
;
i
++
)
for
(
i
=
3
;
i
<
max
;
i
++
)
if
(
i
!=
execfail
[
1
])
close
(
i
);
...
...
@@ -155,7 +156,8 @@ pid_t pipecmdarr(int *fd_tochild, int *fd_fromchild, int *fd_errfromchild,
exit
(
127
);
}
for
(
int
i
=
0
;
i
<
num_par_close
;
i
++
)
int
i
;
for
(
i
=
0
;
i
<
num_par_close
;
i
++
)
close
(
par_close
[
i
]);
/* Child will close this without writing on successful exec. */
...
...
@@ -175,7 +177,7 @@ pid_t pipecmdarr(int *fd_tochild, int *fd_fromchild, int *fd_errfromchild,
return
childpid
;
fail:
for
(
i
nt
i
=
0
;
i
<
num_par_close
;
i
++
)
for
(
i
=
0
;
i
<
num_par_close
;
i
++
)
close_noerr
(
par_close
[
i
]);
return
-
1
;
}
...
...
ccan/str/base32/base32.c
View file @
c16c0217
...
...
@@ -70,7 +70,8 @@ static bool decode_8_chars(const char c[8], beint64_t *res, int *bytes)
{
uint64_t
acc
=
0
;
size_t
num_pad
=
0
;
for
(
int
i
=
0
;
i
<
8
;
i
++
)
{
int
i
;
for
(
i
=
0
;
i
<
8
;
i
++
)
{
const
char
*
p
;
acc
<<=
5
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment