Skip to content

Commit 22b6dee

Browse files
Update exploithawk.c
1 parent a9b042b commit 22b6dee

File tree

1 file changed

+15
-21
lines changed

1 file changed

+15
-21
lines changed

exploithawk.c

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -165,26 +165,20 @@ void *scan_dir_thread(void *arg) {
165165
return NULL;
166166
}
167167

168-
int wrap_text(const char *text, char lines[][MAX_TITLE], int width) {
169-
if (!text) {
170-
lines[0][0] = '\0';
171-
return 1;
172-
}
173-
int len = strlen(text);
174-
if (len == 0) {
175-
lines[0][0] = '\0';
176-
return 1;
177-
}
178-
int count = 0;
179-
int i = 0;
180-
while (i < len && count < 10) {
181-
int chunk = (len - i > width) ? width : len - i;
182-
strncpy(lines[count], text + i, chunk);
183-
lines[count][chunk] = '\0';
184-
count++;
185-
i += chunk;
168+
int wrap_text_generic(const char *text, void *lines, int rows, size_t row_size, int width) {
169+
if (!text || rows <= 0 || row_size < 2) return 1;
170+
if (width > (int)row_size - 1) width = (int)row_size - 1;
171+
if (width <= 0) { ((char*)lines)[0] = '\0'; return 1; }
172+
173+
int len = strlen(text), i = 0, count = 0;
174+
while (i < len && count < rows) {
175+
int chunk = (len - i > width) ? width : (len - i);
176+
char *dest = (char*)lines + (size_t)count * row_size;
177+
memcpy(dest, text + i, chunk);
178+
dest[chunk] = '\0';
179+
count++; i += chunk;
186180
}
187-
return (count == 0) ? 1 : count;
181+
return count ? count : 1;
188182
}
189183

190184
void display_results() {
@@ -251,8 +245,8 @@ void display_results() {
251245
for (int i = start; i < result_count && printed_rows < rows - 3; i++) {
252246
char title_lines[10][MAX_TITLE];
253247
char path_lines[10][MAX_PATH];
254-
int title_count = wrap_text(results[i].title, title_lines, content_title);
255-
int path_count = wrap_text(results[i].path, path_lines, content_path);
248+
int title_count = wrap_text_generic(results[i].title, title_lines, 10, sizeof(title_lines[0]), content_title);
249+
int path_count = wrap_text_generic(results[i].path, path_lines, 10, sizeof(path_lines[0]), content_path);
256250
int max_lines = (title_count > path_count) ? title_count : path_count;
257251

258252
for (int l = 0; l < max_lines && printed_rows < rows - 3; l++) {

0 commit comments

Comments
 (0)