Coverage Report

Created: 2025-09-27 06:35

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/oss-fuzz-example/char_lib.c
Line
Count
Source
1
/* Copyright 2022 Ada Logics ltd.
2
 *
3
 * Licensed under the Apache License, Version 2.0 (the "License");
4
 * you may not use this file except in compliance with the License.
5
 * You may obtain a copy of the License at
6
 *
7
 *    http://www.apache.org/licenses/LICENSE-2.0
8
 *
9
 * Unless required by applicable law or agreed to in writing, software
10
 * distributed under the License is distributed on an "AS IS" BASIS,
11
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
 * See the License for the specific language governing permissions and
13
 * limitations under the License.
14
 */
15
#include <stdlib.h>
16
#include <stdio.h>
17
#include <string.h>
18
19
// Count the number of lowercase letters
20
// input must be a null-terminated string.
21
110
int count_lowercase_letters(char *input) {
22
110
  int length = 0;
23
110
  int lowercase_letters = 0;
24
25
7.33M
  while (1) {
26
7.33M
    if (input[length] == '\0') {
27
110
      break;
28
110
    }
29
7.33M
    length++;
30
7.33M
  }
31
  
32
110
  if (length == 0) {
33
1
    return 0;
34
1
  }
35
36
7.33M
  for (int i = 0; i < length; i++) {
37
7.33M
    if (input[i] >= 0x61 && input[i] <= 0x7a) {
38
6.28M
      lowercase_letters++;
39
6.28M
    }
40
7.33M
  }
41
42
109
  if (lowercase_letters == 42) {
43
1
    printf("wooo\n");
44
1
  }
45
109
  if (lowercase_letters == 0x42) {
46
1
    printf("WOOO!\n");
47
1
  }
48
49
109
  return lowercase_letters;
50
110
}
51
52
57
int get_the_right_character(char *input, int idx) {
53
    // we can't read anything under idx.
54
57
    if (strlen(input) < 40) {
55
10
        return -1;
56
10
    }
57
58
47
    char c = input[idx];
59
47
    if (c == 'X') {
60
1
        return 1;
61
1
    }
62
46
    return -1;
63
47
}
64
65
78
int read_key_figures(char *input, size_t half_length) {
66
78
    if (half_length < 10) {
67
21
        return -1;
68
21
    }
69
70
    // We know half_length is under 10, so we can double it no problem.
71
57
    half_length += half_length;
72
57
    return get_the_right_character(input, half_length);
73
78
}
74
75
298
int parse_complex_format(char *input) {
76
298
    size_t length = strlen(input);
77
298
    if (length < 8) {
78
5
        return -1;
79
5
    }
80
81
293
    if (input[0] != 'F') {
82
14
        return -1;
83
14
    }
84
279
    if (input[1] != 'u') {
85
12
        return -1;
86
12
    }
87
267
    if (input[2] != 'z') {
88
14
        return -1;
89
14
    }
90
253
    if (input[3] != 'z') {
91
11
        return -1;
92
11
    }
93
94
242
    int sum = 0;
95
9.96M
    for (int i = 0; i < length; i++) {
96
9.96M
        if (input[i] > 0x20) {
97
5.55M
            sum += 1;
98
5.55M
        }
99
9.96M
    }
100
101
242
    if (sum < 20) {
102
78
        return read_key_figures(input, length/2);
103
78
    }
104
164
    else {
105
164
        if (sum > 40) {
106
153
            int *magic_ptr = (int*)input;
107
153
            int magic_val1 = magic_ptr[8];
108
153
            int magic_val2 = magic_ptr[9];
109
153
            if (magic_val1 == 0x41424344  && magic_val2 == 0x5b5d5b5d) {
110
1
                return 1;
111
1
            }
112
153
        }
113
164
    }
114
163
    return -1;
115
242
}
116
117
0
int parse_complex_format_second(char *input) {
118
0
    size_t length = strlen(input);
119
0
    if (length < 8) {
120
0
        return -1;
121
0
    }
122
123
0
    if (input[0] != 'F') {
124
0
        return -1;
125
0
    }
126
0
    if (input[1] != 'u') {
127
0
        return -1;
128
0
    }
129
0
    if (input[2] != 'z') {
130
0
        return -1;
131
0
    }
132
0
    if (input[3] != 'z') {
133
0
        return -1;
134
0
    }
135
136
0
    int sum = 0;
137
0
    for (int i = 0; i < length; i++) {
138
0
        if (input[i] > 0x20) {
139
0
            sum += 1;
140
0
        }
141
0
    }
142
143
0
    if (sum < 20) {
144
0
        return read_key_figures(input, (int)((length / 2) -1) );
145
0
    }
146
0
    else {
147
0
        if (sum > 40) {
148
0
            int *magic_ptr = (int*)input;
149
0
            int magic_val1 = magic_ptr[8];
150
0
            int magic_val2 = magic_ptr[9];
151
0
            if (magic_val1 == 0x41424344  && magic_val2 == 0x5b5d5b5d) {
152
0
                return 1;
153
0
            }
154
0
        }
155
0
    }
156
0
    return -1;
157
0
}