<commit_before>#include <stdio.h>
#include <stdlib.h>

struct FreeMem_block{
    int startAddr;
    int length;
    struct FreeMem_block *next;
};

struct FreeMem_block *freeMemBlockList;

void init(){//Init the freeMemBlockList
    struct FreeMem_block *p;
    p = (struct FreeMem_block*)malloc(sizeof(struct FreeMem_block));
    if(p == NULL){
        printf("Error!No enough memory to allocate!\n");
    }
    p->startAddr = 20;
    p->length = 120;
    freeMemBlockList = p;

    struct FreeMem_block *p1 = (struct FreeMem_block*)malloc(sizeof(struct FreeMem_block));
    if(p1 == NULL){
        printf("Error!No enough memory to allocate!\n");
    }
    p1->startAddr = 200;
    p1->length = 100;
    p->next = p1;
    p = p->next;

    struct FreeMem_block *p2 = (struct FreeMem_block*)malloc(sizeof(struct FreeMem_block));
    if(p2 == NULL){
        printf("Error!No enough memory to allocate!\n");
    }
    p2->startAddr = 400;
    p2->length = 60;
    p2->next = NULL;
    p->next = p2;
}
int isNoSpace(){
    if(freeMemBlockList == NULL){
        return 1;
    }else{
        return 0;
    }
}
/*First Fit algorithm
    begin the search from the head of freeMemBlockList, allocate the first block which will satisfy the need
*/
void firstFit(int sizeNeed){
    if( isNoSpace() ){//No space free
        printf("OS has NO FREE SPACE NOW !\n");
        return;
    }
    struct FreeMem_block *p = freeMemBlockList;
    struct FreeMem_block *pr = p;
    int foundFlag = 0;
    while(p != NULL){
        if(p->length > sizeNeed){//freeBlock length > sizeNeed : allocate the space = sizeNeed
            p->startAddr = p->startAddr + sizeNeed;
            p->length = p->length - sizeNeed;

            foundFlag = 1;
            break;
        }else if(p->length == sizeNeed){//freeBlock length = sizeNeed : allocate the whole freeBlock,free the node of the list
            if(p == freeMemBlockList){//the head node
                freeMemBlockList = p->next;
                free(p);
                break;
            }else{
                pr->next = p->next;
                free(p);
            }
<commit_msg>FirstFit bug fixed: display wrong info when the sizeNeed=length and p is the head node<commit_after>#include <stdio.h>
#include <stdlib.h>

struct FreeMem_block{
    int startAddr;
    int length;
    struct FreeMem_block *next;
};

struct FreeMem_block *freeMemBlockList;

void init(){//Init the freeMemBlockList, 3 free blocks in total
    struct FreeMem_block *p;
    p = (struct FreeMem_block*)malloc(sizeof(struct FreeMem_block));
    if(p == NULL){
        printf("Error!No enough memory to allocate!\n");
    }
    p->startAddr = 20;
    p->length = 120;
    freeMemBlockList = p;

    struct FreeMem_block *p1 = (struct FreeMem_block*)malloc(sizeof(struct FreeMem_block));
    if(p1 == NULL){
        printf("Error!No enough memory to allocate!\n");
    }
    p1->startAddr = 200;
    p1->length = 100;
    p->next = p1;
    p = p->next;

    struct FreeMem_block *p2 = (struct FreeMem_block*)malloc(sizeof(struct FreeMem_block));
    if(p2 == NULL){
        printf("Error!No enough memory to allocate!\n");
    }
    p2->startAddr = 400;
    p2->length = 60;
    p2->next = NULL;
    p->next = p2;
}
int isNoSpace(){
    if(freeMemBlockList == NULL){
        return 1;
    }else{
        return 0;
    }
}
/*First Fit algorithm
    begin the search from the head of freeMemBlockList, allocate the first block which will satisfy the need
*/
void firstFit(int sizeNeed){
    if( isNoSpace() ){//No space free
        printf("OS has NO FREE SPACE NOW !\n");
        return;
    }
    struct FreeMem_block *p = freeMemBlockList;
    struct FreeMem_block *pr = p;
    int foundFlag = 0;
    while(p != NULL){
        if(p->length > sizeNeed){//freeBlock length > sizeNeed : allocate the space = sizeNeed
            p->startAddr = p->startAddr + sizeNeed;
            p->length = p->length - sizeNeed;

            foundFlag = 1;
            break;
        }else if(p->length == sizeNeed){//freeBlock length = sizeNeed : allocate the whole freeBlock,free the node of the list
            if(p == freeMemBlockList){//p is the head node
                freeMemBlockList = p->next;
                free(p);
            }else{
                pr->next = p->next;
                free(p);
            }

{'fraction_non_alphanumeric': 0.1206936416184971, 'fraction_numerical': 0.014566473988439306, 'mean_word_length': 2.3353893600616806, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 49, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '624857', 'n_tokens_mistral': 1403, 'n_tokens_neox': 1335, 'n_words': 386}