Add PVS-Studio and cppcheck (and make some fixes detailed in Informe.docx)

Co-authored-by: Ezequiel Bellver <ebellver@itba.edu.ar>
Co-authored-by: Juan Barmasch <jbarmasch@itba.edu.ar>
This commit is contained in:
Santiago Lo Coco 2021-11-02 23:39:01 -03:00
parent 917d377e67
commit ae4eb5db87
60 changed files with 252 additions and 147 deletions

View File

@ -1,3 +1,5 @@
// This is a personal academic project. Dear PVS-Studio, please check it.
// PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
/* BareMetal File System Utility */ /* BareMetal File System Utility */
/* Written by Ian Seyler of Return Infinity */ /* Written by Ian Seyler of Return Infinity */

View File

@ -1,15 +1,15 @@
#ifndef NAIVE_CONSOLE_H // #ifndef NAIVE_CONSOLE_H
#define NAIVE_CONSOLE_H // #define NAIVE_CONSOLE_H
#include <stdint.h> // #include <stdint.h>
void ncPrint(const char * string); // void ncPrint(const char * string);
void ncPrintChar(char character); // void ncPrintChar(char character);
void ncNewline(); // void ncNewline();
void ncPrintDec(uint64_t value); // void ncPrintDec(uint64_t value);
void ncPrintHex(uint64_t value); // void ncPrintHex(uint64_t value);
void ncPrintBin(uint64_t value); // void ncPrintBin(uint64_t value);
void ncPrintBase(uint64_t value, uint32_t base); // void ncPrintBase(uint64_t value, uint32_t base);
void ncClear(); // void ncClear();
#endif // #endif

View File

@ -1,3 +1,5 @@
// This is a personal academic project. Dear PVS-Studio, please check it.
// PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
#include "keyboard.h" #include "keyboard.h"
#define SIZE 1 #define SIZE 1
@ -37,7 +39,8 @@ void testKeyboardInterrupt(unsigned char c) {
if (flagChangeAlt == 0 && flagChangeF1 == 0) { if (flagChangeAlt == 0 && flagChangeF1 == 0) {
flagChangeAlt = 1; flagChangeAlt = 1;
flagChangeF1 = 1; flagChangeF1 = 1;
saveChar('\v'); // saveChar('\v');
saveChar(-1);
return; return;
} else if (c == 0xB8) { } else if (c == 0xB8) {
flagChangeAlt = 1; flagChangeAlt = 1;

View File

@ -1,74 +1,76 @@
#include <naiveConsole.h> // // This is a personal academic project. Dear PVS-Studio, please check it.
// // PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
// #include <naiveConsole.h>
static uint32_t uintToBase(uint64_t value, char *buffer, uint32_t base); // static uint32_t uintToBase(uint64_t value, char *buffer, uint32_t base);
static char buffer[64] = {'0'}; // static char buffer[64] = {'0'};
static uint8_t *const video = (uint8_t *) 0xB8000; // static uint8_t *const video = (uint8_t *) 0xB8000;
static uint8_t *currentVideo = (uint8_t *) 0xB8000; // static uint8_t *currentVideo = (uint8_t *) 0xB8000;
static const uint32_t width = 80; // static const uint32_t width = 80;
static const uint32_t height = 25; // static const uint32_t height = 25;
void ncPrint(const char *string) { // void ncPrint(const char *string) {
for (int i = 0; string[i] != 0; i++) // for (int i = 0; string[i] != 0; i++)
ncPrintChar(string[i]); // ncPrintChar(string[i]);
} // }
void ncPrintChar(char character) { // void ncPrintChar(char character) {
*currentVideo = character; // *currentVideo = character;
currentVideo += 2; // currentVideo += 2;
} // }
void ncNewline() { // void ncNewline() {
do { // do {
ncPrintChar(' '); // ncPrintChar(' ');
} while ((uint64_t)(currentVideo - video) % (width * 2) != 0); // } while ((uint64_t)(currentVideo - video) % (width * 2) != 0);
} // }
void ncPrintDec(uint64_t value) { // void ncPrintDec(uint64_t value) {
ncPrintBase(value, 10); // ncPrintBase(value, 10);
} // }
void ncPrintHex(uint64_t value) { // void ncPrintHex(uint64_t value) {
ncPrintBase(value, 16); // ncPrintBase(value, 16);
} // }
void ncPrintBin(uint64_t value) { // void ncPrintBin(uint64_t value) {
ncPrintBase(value, 2); // ncPrintBase(value, 2);
} // }
void ncPrintBase(uint64_t value, uint32_t base) { // void ncPrintBase(uint64_t value, uint32_t base) {
uintToBase(value, buffer, base); // uintToBase(value, buffer, base);
ncPrint(buffer); // ncPrint(buffer);
} // }
void ncClear() { // void ncClear() {
for (int i = 0; i < height * width; i++) // for (int i = 0; i < height * width; i++)
video[i * 2] = ' '; // video[i * 2] = ' ';
currentVideo = video; // currentVideo = video;
} // }
static uint32_t uintToBase(uint64_t value, char *buffer, uint32_t base) { // static uint32_t uintToBase(uint64_t value, char *buffer, uint32_t base) {
char *p = buffer; // char *p = buffer;
char *p1, *p2; // char *p1, *p2;
uint32_t digits = 0; // uint32_t digits = 0;
do { // do {
uint32_t remainder = value % base; // uint32_t remainder = value % base;
*p++ = (remainder < 10) ? remainder + '0' : remainder + 'A' - 10; // *p++ = (remainder < 10) ? remainder + '0' : remainder + 'A' - 10;
digits++; // digits++;
} while (value /= base); // } while (value /= base);
*p = 0; // *p = 0;
p1 = buffer; // p1 = buffer;
p2 = p - 1; // p2 = p - 1;
while (p1 < p2) { // while (p1 < p2) {
char tmp = *p1; // char tmp = *p1;
*p1 = *p2; // *p1 = *p2;
*p2 = tmp; // *p2 = tmp;
p1++; // p1++;
p2--; // p2--;
} // }
return digits; // return digits;
} // }

View File

@ -1,3 +1,5 @@
// This is a personal academic project. Dear PVS-Studio, please check it.
// PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
#include "time.h" #include "time.h"
static unsigned long ticks = 0; static unsigned long ticks = 0;

View File

@ -1,3 +1,5 @@
// This is a personal academic project. Dear PVS-Studio, please check it.
// PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
#include "video.h" #include "video.h"
static uint8_t *const video = (uint8_t *) 0xB8000; static uint8_t *const video = (uint8_t *) 0xB8000;

View File

@ -1,3 +1,5 @@
// This is a personal academic project. Dear PVS-Studio, please check it.
// PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
#include "exceptions.h" #include "exceptions.h"
static void zero_division(); static void zero_division();

View File

@ -1,3 +1,5 @@
// This is a personal academic project. Dear PVS-Studio, please check it.
// PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
#include "idtLoader.h" #include "idtLoader.h"
#pragma pack(push) #pragma pack(push)

View File

@ -1,3 +1,5 @@
// This is a personal academic project. Dear PVS-Studio, please check it.
// PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
#include "irqDispatcher.h" #include "irqDispatcher.h"
void irqDispatcher(uint64_t irq) { void irqDispatcher(uint64_t irq) {

View File

@ -1,3 +1,5 @@
// This is a personal academic project. Dear PVS-Studio, please check it.
// PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
#include "systemCalls.h" #include "systemCalls.h"
uint64_t write(uint64_t fd, uint64_t buffer, uint64_t length) { uint64_t write(uint64_t fd, uint64_t buffer, uint64_t length) {
@ -36,10 +38,9 @@ uint64_t read(uint64_t fd, uint64_t buffer, uint64_t length) {
blockIO(); blockIO();
} }
readBytes++; readBytes++;
if (*bufferAux++ == '\v') { if (*bufferAux++ == -1) {
break; break;
} }
// blockIO();
} }
} else { } else {
while (length-- > 0) { while (length-- > 0) {
@ -47,12 +48,11 @@ uint64_t read(uint64_t fd, uint64_t buffer, uint64_t length) {
if (*bufferAux == 0) if (*bufferAux == 0)
break; break;
readBytes++; readBytes++;
if (*bufferAux++ == '\v') { if (*bufferAux++ == -1) {
break; break;
} }
} }
} }
// *bufferAux = 0;
return readBytes; return readBytes;
} }

View File

@ -1,3 +1,5 @@
// This is a personal academic project. Dear PVS-Studio, please check it.
// PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
#include "systemCallsDispatcher.h" #include "systemCallsDispatcher.h"
uint64_t systemCallsDispatcher(uint64_t rdi, uint64_t rsi, uint64_t rdx, uint64_t rcx, uint64_t r8, uint64_t r9) { uint64_t systemCallsDispatcher(uint64_t rdi, uint64_t rsi, uint64_t rdx, uint64_t rcx, uint64_t r8, uint64_t r9) {
@ -14,7 +16,7 @@ uint64_t systemCallsDispatcher(uint64_t rdi, uint64_t rsi, uint64_t rdx, uint64_
exitProcess(); exitProcess();
break; break;
case 5: case 5:
return dumpMM(); return (uint64_t) dumpMM();
case 6: case 6:
return (uint64_t) processes(); return (uint64_t) processes();
case 7: case 7:
@ -51,11 +53,15 @@ uint64_t systemCallsDispatcher(uint64_t rdi, uint64_t rsi, uint64_t rdx, uint64_
case 20: case 20:
return unblock(rsi); return unblock(rsi);
case 21: case 21:
return wait(); wait();
break;
case 22: case 22:
return pipes(); return (uint64_t) pipes();
case 23: case 23:
return quitCPU(); return quitCPU();
case 24:
closePipe(rsi);
break;
default: default:
return -1; return -1;
} }

View File

@ -1,3 +1,5 @@
// This is a personal academic project. Dear PVS-Studio, please check it.
// PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
#include <stdint.h> #include <stdint.h>
#include <lib.h> #include <lib.h>
#include <moduleLoader.h> #include <moduleLoader.h>

View File

@ -1,3 +1,5 @@
// This is a personal academic project. Dear PVS-Studio, please check it.
// PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
#include "lib.h" #include "lib.h"
void *memset(void *destination, int32_t c, uint64_t length) { void *memset(void *destination, int32_t c, uint64_t length) {

View File

@ -1,3 +1,5 @@
// This is a personal academic project. Dear PVS-Studio, please check it.
// PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
#include <stdint.h> #include <stdint.h>
#include <lib.h> #include <lib.h>
#include <moduleLoader.h> #include <moduleLoader.h>

View File

@ -25,5 +25,6 @@ char openPipe(int * fds, char * name);
void writePipe(int fd, char c); void writePipe(int fd, char c);
char readPipe(int fd); char readPipe(int fd);
char * pipes(); char * pipes();
void closePipe(int fd);
#endif #endif

View File

@ -21,5 +21,7 @@ void sleep(int secs);
char blockIO(); char blockIO();
void unblockIO(); void unblockIO();
char getState(int pid); char getState(int pid);
char isForeground();
void wait();
#endif #endif

View File

@ -1,3 +1,5 @@
// This is a personal academic project. Dear PVS-Studio, please check it.
// PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
#ifdef BUDDY #ifdef BUDDY
// Basado en: https://github.com/cloudwu/buddy/blob/master/buddy.c // Basado en: https://github.com/cloudwu/buddy/blob/master/buddy.c
@ -83,10 +85,9 @@ void * buddy_alloc(int s) {
int index = 0; int index = 0;
int level = 0; int level = 0;
int nextStep = 1;
while (index >= 0) { while (index >= 0) {
nextStep = 1; int nextStep = 1;
if (size == length) { if (size == length) {
if (self.tree[index] == NODE_UNUSED) { if (self.tree[index] == NODE_UNUSED) {
self.tree[index] = NODE_USED; self.tree[index] = NODE_USED;
@ -181,50 +182,12 @@ int buddy_free(void * pointer) {
} }
} }
// char *dumpMM() {
// return NULL;
// }
uint64_t getSize(int level, int max_level) { uint64_t getSize(int level, int max_level) {
return (1 << (max_level - level)) * PAGE_SIZE; return (1 << (max_level - level)) * PAGE_SIZE;
} }
/*
void buddy_dumpMM(struct buddy * self, int index , int level) {
char buffer[10];
switch (self->tree[index]) {
case NODE_UNUSED:
printStringLen(15, "(_", 1);
printStringLen(15, itoa(getSize(level, self->level), buffer, 10), 0);
printStringLen(15, ":", 1);
printStringLen(15, itoa(level, buffer, 10), 10);
printStringLen(15, "_)", 1);
break;
case NODE_USED:
printStringLen(15, "(*", 1);
printStringLen(15, itoa(getSize(level, self->level), buffer, 10), 10);
printStringLen(15, ":", 1);
printStringLen(15, itoa(level, buffer, 10), 10);
printStringLen(15, "*)", 1);
break;
case NODE_FULL:
printStringLen(15, "[", 1);
buddy_dumpMM(self, index * 2 + 1, level + 1);
buddy_dumpMM(self, index * 2 + 2, level + 1);
printStringLen(15, "]", 1);
break;
default:
printStringLen(15, "(", 1);
buddy_dumpMM(self, index * 2 + 1, level + 1);
buddy_dumpMM(self, index * 2 + 2, level + 1);
printStringLen(15, ")", 1);
break;
}
}
*/
#include <stddef.h> #include <stddef.h>
void buddy_dumpMM(int index , int level, uint64_t *size, uint64_t *used) { void buddy_dumpMM(int index , int level, uint64_t *size, uint64_t *used) {
char buffer[10];
switch (self.tree[index]) { switch (self.tree[index]) {
case NODE_UNUSED: case NODE_UNUSED:
*size += getSize(level, self.level); *size += getSize(level, self.level);

View File

@ -1,3 +1,5 @@
// This is a personal academic project. Dear PVS-Studio, please check it.
// PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
#ifndef BUDDY #ifndef BUDDY
#include "memManagerFRT4.h" #include "memManagerFRT4.h"
@ -118,7 +120,6 @@ void *pvPortMalloc(size_t xWantedSize) {
} }
/*-----------------------------------------------------------*/ /*-----------------------------------------------------------*/
void vPortFree(void *pv) { void vPortFree(void *pv) {
uint8_t *puc = (uint8_t *) pv; uint8_t *puc = (uint8_t *) pv;
BlockLink_t *pxLink; BlockLink_t *pxLink;

View File

@ -1,3 +1,5 @@
// This is a personal academic project. Dear PVS-Studio, please check it.
// PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
#include "pipe.h" #include "pipe.h"
static int fdIndex = 2; static int fdIndex = 2;

View File

@ -1,7 +1,9 @@
// This is a personal academic project. Dear PVS-Studio, please check it.
// PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
#include "scheduler.h" #include "scheduler.h"
enum states { enum states {
READY = 0, DEAD, BLOCKED, BBCHILDREN, WAITING, BLOCKEDIO READY = 0, DEAD, BLOCKED, WAITING, BLOCKEDIO
}; };
typedef struct processCDT { typedef struct processCDT {
@ -18,6 +20,7 @@ typedef struct processCDT {
int *fd; int *fd;
int children; int children;
char backWait; char backWait;
uint64_t bPointer;
} processCDT; } processCDT;
typedef struct sleepCDT { typedef struct sleepCDT {
@ -56,7 +59,6 @@ void removeProcess(processCDT *del, processCDT **first, processCDT **last) {
uint64_t nextProcess(uint64_t currentRSP) { uint64_t nextProcess(uint64_t currentRSP) {
if (currentProcess != NULL) if (currentProcess != NULL)
currentProcess->rsp = currentRSP; currentProcess->rsp = currentRSP;
processCDT *prev = currentProcess;
if (currentProcess != NULL && currentProcess->state == READY && if (currentProcess != NULL && currentProcess->state == READY &&
currentProcess->executions == MAX_PRIORITY - currentProcess->priority) { currentProcess->executions == MAX_PRIORITY - currentProcess->priority) {
currentProcess->executions = 0; currentProcess->executions = 0;
@ -69,7 +71,6 @@ uint64_t nextProcess(uint64_t currentRSP) {
} else if (currentProcess == firstBlockedIteration) { } else if (currentProcess == firstBlockedIteration) {
idleFlag = 1; idleFlag = 1;
unblock(IDLE_PID); unblock(IDLE_PID);
prev = currentProcess;
currentProcess = currentProcess->next; currentProcess = currentProcess->next;
} else if (currentProcess->state == DEAD) { } else if (currentProcess->state == DEAD) {
processCDT *del = currentProcess; processCDT *del = currentProcess;
@ -80,7 +81,6 @@ uint64_t nextProcess(uint64_t currentRSP) {
currentProcess->state == BLOCKEDIO) { currentProcess->state == BLOCKEDIO) {
if (firstBlockedIteration == NULL) if (firstBlockedIteration == NULL)
firstBlockedIteration = currentProcess; firstBlockedIteration = currentProcess;
prev = currentProcess;
currentProcess = currentProcess->next; currentProcess = currentProcess->next;
} }
} }
@ -149,6 +149,7 @@ int enqueueProcess(void (*fn)(int, char **), char foreground, int argc, char *ar
process->next = NULL; process->next = NULL;
process->children = 0; process->children = 0;
process->backWait = 0; process->backWait = 0;
process->bPointer = (uint64_t) auxi;
process->rsp = _initialize_stack_frame(fn, rbp, argc, argv); process->rsp = _initialize_stack_frame(fn, rbp, argc, argv);
@ -341,8 +342,8 @@ char kill(int pid) {
vPortFree(del->fd); vPortFree(del->fd);
vPortFree(del->name); vPortFree(del->name);
void *auxi = del->rbp - STACK_SIZE; // vPortFree((void *) ((uint64_t) del->rbp - STACK_SIZE));
vPortFree((void *) auxi); vPortFree((void *) del->bPointer);
del->state = DEAD; del->state = DEAD;
if (pid == currentProcess->pid) { if (pid == currentProcess->pid) {

View File

@ -1,3 +1,5 @@
// This is a personal academic project. Dear PVS-Studio, please check it.
// PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
#include "sem.h" #include "sem.h"
static uint32_t semLock; static uint32_t semLock;
@ -40,6 +42,8 @@ sem_t *semOpen(char *name, unsigned int value) {
sem->name = pvPortMalloc(MAX_NAME); sem->name = pvPortMalloc(MAX_NAME);
strcpy(sem->name, name); strcpy(sem->name, name);
sem->value = value; sem->value = value;
sem->entering = NULL;
sem->last = NULL;
counter++; counter++;
leave_region(&semLock); leave_region(&semLock);

View File

@ -37,4 +37,10 @@ clean:
cd Kernel; make clean cd Kernel; make clean
cd Userland; make clean cd Userland; make clean
.PHONY: bootloader image imageSpanish imageBuddy collections kernel kernelSpanish kernelBuddy userland all clean test:
pvs-studio-analyzer trace -- make
pvs-studio-analyzer analyze
plog-converter -a '64:1,2,3;GA:1,2,3;OP:1,2,3' -t tasklist -o report.tasks PVS-Studio.log
cppcheck --quiet --enable=all --force --inconclusive .
.PHONY: bootloader image imageSpanish imageBuddy collections kernel kernelSpanish kernelBuddy userland all clean test

View File

@ -1,3 +1,5 @@
// This is a personal academic project. Dear PVS-Studio, please check it.
// PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
#include <stdio.h> #include <stdio.h>
#include <unistd.h> #include <unistd.h>
#include <stdint.h> #include <stdint.h>

View File

@ -1,3 +1,5 @@
// This is a personal academic project. Dear PVS-Studio, please check it.
// PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
#include <stdint.h> #include <stdint.h>
extern char bss; extern char bss;

View File

@ -3,7 +3,7 @@ GLOBAL _getMem, sys_loadProcess
GLOBAL raiseOpcodeExc GLOBAL raiseOpcodeExc
GLOBAL _getRegs, sys_switchContext GLOBAL _getRegs, sys_switchContext
GLOBAL cpu_id, cpu_id_support GLOBAL cpu_id, cpu_id_support
GLOBAL sys_exit, sys_ps, sys_free, sys_malloc, sys_sem, sys_openPipe, sys_semClose GLOBAL sys_exit, sys_ps, sys_free, sys_malloc, sys_sem, sys_openPipe, sys_closePipe, sys_semClose
GLOBAL sys_nice, sys_semWait, sys_semPost, sys_semOpen, sys_sleep, sys_kill, sys_getPid, GLOBAL sys_nice, sys_semWait, sys_semPost, sys_semOpen, sys_sleep, sys_kill, sys_getPid,
GLOBAL sys_block, sys_unblock, sys_wait, sys_pipes, sys_quitCPU, sys_dumpMM GLOBAL sys_block, sys_unblock, sys_wait, sys_pipes, sys_quitCPU, sys_dumpMM
@ -78,6 +78,24 @@ sys_openPipe:
pop rbp pop rbp
ret ret
sys_closePipe:
push rbp
mov rbp, rsp
push rdi
push rsi
mov rsi, rdi
mov rdi, 24
int 80h
pop rsi
pop rdi
mov rsp, rbp
pop rbp
ret
sys_exit: sys_exit:
push rbp push rbp
mov rbp, rsp mov rbp, rsp

View File

@ -1,3 +1,5 @@
// This is a personal academic project. Dear PVS-Studio, please check it.
// PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
#include "bottler.h" #include "bottler.h"
void bottler(int argc, char **argv) { void bottler(int argc, char **argv) {

View File

@ -36,5 +36,7 @@ char sys_unblock(int pid);
void sys_quitCPU(); void sys_quitCPU();
void sys_wait(); void sys_wait();
char * sys_dumpMM(); char * sys_dumpMM();
char * sys_pipes();
void sys_closePipe();
#endif #endif

View File

@ -154,7 +154,7 @@ char *itoa(int value, char *buffer, int base) {
} }
int atoi(char *str, int length) { int atoi(char *str, int length) {
int i = 0, sign = 1, val = 0, nbr = 0; int i = 0, sign = 1, val = 0;
while (str[i] != '\0') { while (str[i] != '\0') {
if (str[i] == '-') { if (str[i] == '-') {
sign = -sign; sign = -sign;
@ -164,7 +164,7 @@ int atoi(char *str, int length) {
} }
i = 0; i = 0;
while (str[i] >= '0' && str[i] <= '9' && str[i] != '\0') { while (str[i] >= '0' && str[i] <= '9' && str[i] != '\0') {
nbr = (int) (str[i] - '0'); int nbr = (int) (str[i] - '0');
val = (val * 10) + nbr; val = (val * 10) + nbr;
i++; i++;
} }

View File

@ -1,3 +1,5 @@
// This is a personal academic project. Dear PVS-Studio, please check it.
// PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
#include "libc.h" #include "libc.h"
#include "shell/include/shell.h" #include "shell/include/shell.h"
#include "bottler/include/bottler.h" #include "bottler/include/bottler.h"

View File

@ -1,3 +1,5 @@
// This is a personal academic project. Dear PVS-Studio, please check it.
// PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
#include "block.h" #include "block.h"
void block(int argc, char ** argv) { void block(int argc, char ** argv) {

View File

@ -1,14 +1,20 @@
// This is a personal academic project. Dear PVS-Studio, please check it.
// PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
#include "cat.h" #include "cat.h"
#define SIZE 1000 #define SIZE 1000
void debug2() {
return;
}
void cat(int argc, char ** argv) { void cat(int argc, char ** argv) {
char c; char c;
int i = 0, j = 0, line = 0; int i = 0, j = 0, line = 0;
char buffer[SIZE] = {0}; char buffer[SIZE] = {0};
while ((c = getChar()) > 0) { while ((c = getChar()) > 0) {
if (i >= SIZE) if (i > SIZE - 1)
break; break;
buffer[i++] = c; buffer[i++] = c;
j++; j++;
@ -22,6 +28,10 @@ void cat(int argc, char ** argv) {
buffer[--i] = 0; buffer[--i] = 0;
} }
} }
buffer[i++] = c;
j++;
debug2();
printStringLen(buffer + line, j); printStringLen(buffer + line, j);
newline(); newline();

View File

@ -1,3 +1,5 @@
// This is a personal academic project. Dear PVS-Studio, please check it.
// PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
#include "libc.h" #include "libc.h"
#include "shell.h" #include "shell.h"
#include "clear.h" #include "clear.h"

View File

@ -1,3 +1,5 @@
// This is a personal academic project. Dear PVS-Studio, please check it.
// PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
#include "cpu_id.h" #include "cpu_id.h"
int cpu_id(int *, int *, int *, int *); int cpu_id(int *, int *, int *, int *);

View File

@ -1,3 +1,5 @@
// This is a personal academic project. Dear PVS-Studio, please check it.
// PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
#include "excDiv.h" #include "excDiv.h"
void excdiv(int argc, char *argv[]) { void excdiv(int argc, char *argv[]) {

View File

@ -1,3 +1,5 @@
// This is a personal academic project. Dear PVS-Studio, please check it.
// PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
#include "excOP.h" #include "excOP.h"
void raiseOpcodeExc(); void raiseOpcodeExc();

View File

@ -1,3 +1,5 @@
// This is a personal academic project. Dear PVS-Studio, please check it.
// PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
#include "filter.h" #include "filter.h"
#define SIZE 1000 #define SIZE 1000
@ -28,6 +30,8 @@ void filter(int argc, char ** argv) {
line = i; line = i;
} }
} }
buffer[i++] = c;
j++;
printStringLen(buffer + line, j); printStringLen(buffer + line, j);

View File

@ -1,3 +1,5 @@
// This is a personal academic project. Dear PVS-Studio, please check it.
// PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
#include "libc.h" #include "libc.h"
#include "shell.h" #include "shell.h"

View File

@ -1,3 +1,5 @@
// This is a personal academic project. Dear PVS-Studio, please check it.
// PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
#include "inforeg.h" #include "inforeg.h"
#include <stdint.h> #include <stdint.h>
#include "libc.h" #include "libc.h"

View File

@ -1,3 +1,5 @@
// This is a personal academic project. Dear PVS-Studio, please check it.
// PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
#include "kill.h" #include "kill.h"
void kill(int argc, char ** argv) { void kill(int argc, char ** argv) {

View File

@ -1,3 +1,5 @@
// This is a personal academic project. Dear PVS-Studio, please check it.
// PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
#include "loop.h" #include "loop.h"
#define PUAN -1 #define PUAN -1

View File

@ -1,3 +1,5 @@
// This is a personal academic project. Dear PVS-Studio, please check it.
// PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
#include "libc.h" #include "libc.h"
#include "shell.h" #include "shell.h"

View File

@ -1,3 +1,5 @@
// This is a personal academic project. Dear PVS-Studio, please check it.
// PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
#include "nice.h" #include "nice.h"
void nice(int argc, char ** argv) { void nice(int argc, char ** argv) {

View File

@ -1,3 +1,5 @@
// This is a personal academic project. Dear PVS-Studio, please check it.
// PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
#include "phyloLib.h" #include "phyloLib.h"
philosopher_t *firstPhil; philosopher_t *firstPhil;
@ -120,7 +122,6 @@ void phylo(int argc, char ** argv) {
philosopher_t * left = NULL; philosopher_t * left = NULL;
for (int i = 0; i < philoCount; i++) { for (int i = 0; i < philoCount; i++) {
philosopher_t * phil = sys_malloc(sizeof(philosopher_t)); philosopher_t * phil = sys_malloc(sizeof(philosopher_t));
phil->debug = i;
phil->argv = sys_malloc(sizeof(char *) * 2); phil->argv = sys_malloc(sizeof(char *) * 2);
phil->buffer = sys_malloc(20); phil->buffer = sys_malloc(20);
phil->state = THINKING; phil->state = THINKING;

View File

@ -1,3 +1,5 @@
// This is a personal academic project. Dear PVS-Studio, please check it.
// PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
#include "pipes.h" #include "pipes.h"
void pipe(int argc, char *argv[]) { void pipe(int argc, char *argv[]) {

View File

@ -1,3 +1,5 @@
// This is a personal academic project. Dear PVS-Studio, please check it.
// PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
#include "inforeg.h" #include "inforeg.h"
#include <stdint.h> #include <stdint.h>
#include "shell.h" #include "shell.h"

View File

@ -1,3 +1,5 @@
// This is a personal academic project. Dear PVS-Studio, please check it.
// PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
#include "libc.h" #include "libc.h"
#include "shell.h" #include "shell.h"

View File

@ -1,3 +1,5 @@
// This is a personal academic project. Dear PVS-Studio, please check it.
// PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
#include "libc.h" #include "libc.h"
#include "quadratic.h" #include "quadratic.h"
#include "shell.h" #include "shell.h"

View File

@ -1,3 +1,5 @@
// This is a personal academic project. Dear PVS-Studio, please check it.
// PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
#include "libc.h" #include "libc.h"
#include "shell.h" #include "shell.h"

View File

@ -1,5 +1,9 @@
// This is a personal academic project. Dear PVS-Studio, please check it.
// PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
#include "test_mm.h" #include "test_mm.h"
void *memset(void *destination, int32_t c, uint64_t length);
typedef struct MM_rq{ typedef struct MM_rq{
void *address; void *address;
uint32_t size; uint32_t size;

View File

@ -1,3 +1,5 @@
// This is a personal academic project. Dear PVS-Studio, please check it.
// PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
#include "test_prio.h" #include "test_prio.h"
#define MINOR_WAIT 10000000 // TODO: To prevent a process from flooding the screen #define MINOR_WAIT 10000000 // TODO: To prevent a process from flooding the screen

View File

@ -1,3 +1,5 @@
// This is a personal academic project. Dear PVS-Studio, please check it.
// PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
#include "test_processes.h" #include "test_processes.h"
#include "ps.h" #include "ps.h"
@ -16,10 +18,6 @@ void endless_loop(){
sys_exit(); sys_exit();
} }
void debugPSA() {
return;
}
void test_processes(int argc, char ** argv){ void test_processes(int argc, char ** argv){
p_rq p_rqs[MAX_PROCESSES]; p_rq p_rqs[MAX_PROCESSES];
uint8_t rq; uint8_t rq;

View File

@ -1,3 +1,5 @@
// This is a personal academic project. Dear PVS-Studio, please check it.
// PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
#include "test_sync.h" #include "test_sync.h"
#define TOTAL_PAIR_PROCESSES 2 #define TOTAL_PAIR_PROCESSES 2
@ -25,11 +27,10 @@ void inc(int argc, char ** argv) {
uint64_t N = atoi(argv[3], 10); uint64_t N = atoi(argv[3], 10);
uint64_t i; uint64_t i;
char buff[10] = {0};
for (i = 0; i < N; i++){ for (i = 0; i < N; i++){
if (semDir) sys_semWait(semDir); if (semDir) sys_semWait((sem_t *) semDir);
slowInc(&global, value); slowInc(&global, value);
if (semDir) sys_semPost(semDir); if (semDir) sys_semPost((sem_t *) semDir);
} }
char buffer[10] = {0}; char buffer[10] = {0};
@ -48,7 +49,7 @@ void test_sync(int argc, char ** argv){
sem_t * sem = sys_semOpen(SEM_ID, 1); sem_t * sem = sys_semOpen(SEM_ID, 1);
char semDir[10] = {0}; char semDir[10] = {0};
itoa((int) sem, semDir, 10); itoa((uint64_t) sem, semDir, 10);
for(i = 0; i < TOTAL_PAIR_PROCESSES; i++){ for(i = 0; i < TOTAL_PAIR_PROCESSES; i++){
char * argv1[] = {"inc", semDir, "1", ITERS}; char * argv1[] = {"inc", semDir, "1", ITERS};

View File

@ -1,3 +1,5 @@
// This is a personal academic project. Dear PVS-Studio, please check it.
// PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
#include <stdint.h> #include <stdint.h>
#include "test_util.h" #include "test_util.h"

View File

@ -1,3 +1,5 @@
// This is a personal academic project. Dear PVS-Studio, please check it.
// PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
#include "time.h" #include "time.h"
#include "libc.h" #include "libc.h"
#include "shell.h" #include "shell.h"

View File

@ -1,3 +1,5 @@
// This is a personal academic project. Dear PVS-Studio, please check it.
// PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
#include "unblock.h" #include "unblock.h"
void unblock(int argc, char ** argv) { void unblock(int argc, char ** argv) {

View File

@ -1,3 +1,5 @@
// This is a personal academic project. Dear PVS-Studio, please check it.
// PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
#include "wc.h" #include "wc.h"
#define SIZE 1000 #define SIZE 1000
@ -12,6 +14,7 @@ void wc(int argc, char ** argv) {
if (c == '\n') if (c == '\n')
i++; i++;
} }
buffer[i++] = c;
printStringLen(gtoa(i, buffer, 10, SIZE), SIZE); printStringLen(gtoa(i, buffer, 10, SIZE), SIZE);
newline(); newline();

View File

@ -17,7 +17,6 @@ int * state;
typedef enum states {EATING = 0, HUNGRY, THINKING} states; typedef enum states {EATING = 0, HUNGRY, THINKING} states;
typedef struct philosopher_t { typedef struct philosopher_t {
int debug;
char ** argv; char ** argv;
char * buffer; char * buffer;
sem_t * sem; sem_t * sem;
@ -29,5 +28,7 @@ typedef struct philosopher_t {
} philosopher_t; } philosopher_t;
void philosopher(int argc, char ** argv); void philosopher(int argc, char ** argv);
void freePhilo(philosopher_t * phil);
void end();
#endif #endif

View File

@ -1,3 +1,5 @@
// This is a personal academic project. Dear PVS-Studio, please check it.
// PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
#include "shell.h" #include "shell.h"
cmd_t commands[] = { cmd_t commands[] = {
@ -144,9 +146,11 @@ void processInput(char *input) {
if (commands[comm0].isForeground) { if (commands[comm0].isForeground) {
sys_wait(); sys_wait();
}
sys_free(argv0); sys_free(argv0);
if (pipe == -1) if (pipe != -1) {
sys_free(argv1); sys_free(argv1);
sys_closePipe(fd1[1]);
} }
} }

View File

@ -12,6 +12,8 @@ cd ..
if [ $# -eq 1 ]; then if [ $# -eq 1 ]; then
if [ $1 = "buddy" ]; then if [ $1 = "buddy" ]; then
make buddy make buddy
elif [ $1 = "spanish" ]; then
make spanish
else else
echo "Do you want to compile with the buddy memory manager? if so, you must pass buddy as argument" echo "Do you want to compile with the buddy memory manager? if so, you must pass buddy as argument"
fi fi

View File

@ -1 +1 @@
be ke