Skip to content

Commit ffe457b

Browse files
committed
Fix head
1 parent 9f7bed8 commit ffe457b

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

src/copy_data.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,12 @@ bool copy_data_value(dataframe_t *dst, dataframe_t *src, int row)
5555
__attribute__((nonnull(1, 2)))
5656
bool copy_data(dataframe_t *dst, dataframe_t *src, int nb_rows)
5757
{
58+
int row = 0;
59+
5860
dst->data = (void ***)malloc(sizeof(void *) * nb_rows);
5961
if ((void *)dst->data == NULL)
6062
return false;
61-
for (int row = 0; row < nb_rows; row++) {
63+
for (; row < nb_rows && row < src->nb_rows; row++) {
6264
dst->data[row] = (void **)malloc(sizeof(void *) * src->nb_columns);
6365
#pragma GCC diagnostic push
6466
#pragma GCC diagnostic ignored "-Wanalyzer-malloc-leak"
@@ -68,5 +70,6 @@ bool copy_data(dataframe_t *dst, dataframe_t *src, int nb_rows)
6870
return (free((void *)dst->data), false);
6971
#pragma GCC diagnostic pop
7072
}
73+
dst->nb_rows = row + 1;
7174
return true;
7275
}

src/df_head.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ dataframe_t *df_head(dataframe_t *df, int nb_rows)
2121
if (new_df == NULL)
2222
return NULL;
2323
new_df->nb_columns = df->nb_columns;
24-
new_df->nb_rows = nb_rows;
2524
if (!copy_columns_type(new_df, df) || !copy_columns_name(new_df, df) ||
2625
!copy_data(new_df, df, nb_rows))
2726
return (free(new_df), NULL);

0 commit comments

Comments
 (0)