407,025 questions
0
votes
0
answers
10
views
Roadmap to Build a Simple and Secure Pass Manager in C [closed]
I want to build a simple and secure pass manager (like keepass, vaultwarden) in C. But i dont know where i should start.
Would you give me a roadmap of that?
Thank you!
I know little bit of c ...
4
votes
2
answers
50
views
Is it OK to use longjmp to break out of qsort?
In In the middle of qsort, is there a way to stop it? some comments mentioned using setjmp/longjmp to break out of a call to qsort() from the comparison function.
The language specification doesn't ...
0
votes
2
answers
57
views
Freeing a dynamically allocated string with an internal null byte
The following code allocates 256 bytes for a character array and then replaces the space with \0 (similar to what strtok and strsep do).
#include <stdlib.h>
#include <string.h>
int main() ...
0
votes
1
answer
40
views
Intentionally Disregarding Excess Elements in Initializer Warning Under GCC
I am attempting to abuse static initialization to build a menu tree without any runtime initialization:
typedef struct {
menu_entry_t entry;
uint16_t can_loop:1;
uint16_t sz:15;
...
1
vote
0
answers
21
views
How to get debuginfod for GDB MSYS2?
I have been trying to run GDP to debug a Tcl C extension using the command gdb tclsh - but the MSYS2 version of GDB says that Support for debuginfod is not compiled into GDB. and outputs Reading ...
0
votes
1
answer
115
views
In the middle of qsort, is there a way to stop it?
qsort is an essential part of the standard C library in all platforms. In the compare function introduced to this function, I may conclude that two items are identical and I decide not to continue the ...
1
vote
0
answers
43
views
How do I find addresses 1, 2, and 3 on the stack using gdb?
What are the addresses for the locations in the image and how can I find them using gdb?
My assumption:
Location 1: no clue
Location 2: $eip / $ebp+4 at break myprintf
Location 3: printf("The ...
0
votes
1
answer
63
views
Why is this code still adding 1 to i even when the if statment that does so isnt called in C?
So this is my code:
#include <stdio.h>
#define SIZE 10
int main(void)
{
int x,p[SIZE],i=0;
printf("type some characters\n");
while((x = getchar()) != EOF && i<...
1
vote
2
answers
97
views
Case insensitive version of strstr() [closed]
In order to solve a problem from K&R C book, I am trying to write a function strstrci() which is the case insensitive version of strstr()
char * strstrci (char *s, char *p)
{
int i, j;
...
1
vote
1
answer
65
views
C static local variable, volatile required or not if function called from different non-concurrent ISRs?
I have a private function that does operations on a static local variable. This function is called from different non-concurrent hardware ISRs. Instinctively, I would believe this to be correct since ...
2
votes
1
answer
63
views
C re-initializing a variable after using strtok
I'm trying to write a function to search in the PATH directories. I used getenv("PATH") to get the path string, then used strtok() to split it.
The second time I call my function it does not ...
2
votes
1
answer
26
views
Tiva C DevBoard - Microcontroller doesn't enter main function
I am working with a Tiva C EK-TM4C123GXL development board (MCU -> TM4C123GH6P). I am using Keil uVision 5, ARM compiler 6.12 and CMSIS pack for this specific microcontroller.
My code is following:
...
1
vote
0
answers
19
views
Linux PCI iomem catch mem access errors in device driver
I have device on embedded CPU ls1043 running OS Linux (custom build on 4.14 kernel). CPU connected to FPGA with PCI 3.0 x1.
In FPGA only BAR 0 with all internal register space. But, not all addresses ...
1
vote
0
answers
27
views
How to render the display for the chip8 implementation
hi guy's so i've been working on this chip8 emulator and I'm half done with finishing the project. the issue i'm having is how to render the display via sdl. i know how to create a window and display ...
0
votes
0
answers
24
views
Linux PCI express device driver segfault on remove
I have device controlled by NXP LS1043 64-bit ARM core CPU. Custom board. CPU connected via PCI 3.0 x 1 (2.5GT/s) to FPGA.
On cold start CPU loaded without PCI device on FPGA side, flash FPGA and ...
0
votes
0
answers
65
views
what shoud I do for "suggest parentheses around comparison in operand of '==' [-Wparentheses]"? [duplicate]
if ((board[0][0]) == (board[0][1]) == (board[0][2])){
return 1;
}
if ((board[1][0]) == (board[1][1]) == (board[1][2])){
return 2;
}
if ((board[2][0]) == (board[2][1]) ==...
0
votes
0
answers
37
views
Python client 'recv()' hangs when receiving data from C socket server
I have a simple C server and a Python client. When I send a message from the server, the Python client's recv() call never returns, even though the server appears to send the data successfully. All ...
2
votes
0
answers
50
views
Semantic patch to add void argument to empty function declarations
Have a codebase full of functions that take no parameters omit the void argument which is producing around 500 warnings when I try to enable -Wextra.
I want to write a semantic patch for e.g. ...
0
votes
1
answer
23
views
Why does disabling echo on WSL2 not work?
I compile and run the C program below on WSL2 Ubuntu, it's supposed to turn echo off on standard input, let the user type a line of text, show them what they typed, and turn echo back on. But the ...
1
vote
2
answers
43
views
How to organize the receive msg and user current input in C network such that it's clean
The program has two threads, one to handle send, one to handle recv. User will always be prompted with fgets() to input message for send. Meanwhile, the recv thread will display the message sent to ...
1
vote
0
answers
39
views
Pitch shifting in frequencies from frequency+amplitude+phase [closed]
I have a (C) code that extracts a list of (frequency + amplitude + phase) from an audio (time-based) signal. From that list I'm able to rebuild the original time-based signal with a very good ...
1
vote
0
answers
51
views
STM32 basic UART bare metal setup issue
I am new here, first post, so thanks in advance for being gentle with me :)
After spending weeks trying to make this work and searching examples/education/forum, i now reach out and hope someone is ...
0
votes
0
answers
56
views
How to correctly use memory mapped circular buffers without miscompilations [closed]
I tried compiling this code on gcc with -O3
#include <assert.h>
#include <stdint.h>
void square(uint8_t *array) {
assert(array[0] == 8);
array[1 << 15] = 4;
assert(array[...
-1
votes
0
answers
35
views
segfualt in C with GPU driver in vulkan [closed]
Unhandled exception at 0x00007FFE82E30508 (nvoglv64.dll) in Voxalith.exe: 0xC0000005: Access violation reading location 0x0000000000002068. I am writing a Vulkan application in C this file is device.c ...
1
vote
0
answers
15
views
Yocto Project: Linking a Shared Library to a Package Results in "library_common.h: No such file or directory" Error
I'm working on a Yocto project and need to create and link a shared library to one of the packages. The directory structure of the shared library source code is as follows:
library
├── svc
│ ├── src
...
1
vote
0
answers
28
views
How to compile sqlite3 source code for debugging in vscode
I have cloned sqlite3 codebase from github and ran following command on folder.
./configure --disable-amalgamation --debug
After that I have ran following command to build
make sqlite3
sqlite3 is ...
0
votes
1
answer
53
views
How make this text consistently line up? [duplicate]
I'm trying to display a row of data, I want to display the data neatly. I used \t, but using tab is inconsistent:
Current output (roughly):
Location City Price ...
0
votes
1
answer
33
views
Why does codeblocks memory dump window not show the error?
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
struct train
{
int id;
int hours;
int minutes;
char destination[21];
};
// ...
1
vote
2
answers
92
views
In this code, why is scanf() not setting the input to the variable properly?
I am trying to post this to the C board. If I am in the wrong place, or this is not an appropriate question please let me know so can delete or move this. Thank you very much.
I am learning C as my ...
-4
votes
0
answers
54
views
zrle compression in C/C++ [closed]
I sniffed my VNC client and got a paylod of bytes that is ZLRE compressed VNC data. I want to decompress it, yet I dont know how to. I got this byte payload using wireshark and sniffing my unencryped ...
-1
votes
0
answers
41
views
Programming µcontroller (CH552): clock_t gives syntax in .c [closed]
I googled this question and found quite a lot of topics, but nothing has helped thus far.
I have a macropad from a certain website for cheap and wrote other firmware over it through code I got off a ...
0
votes
1
answer
92
views
Is dividing an integer with value 0x80000000 an UB?
Here is the code
printf("%d", 0x80000000 / 10).
It prints a correct value with respect to its absolute value, but forgets to put a minus sign. Let's check if the original integer (signed) is ...
4
votes
3
answers
82
views
GCC C99 Disable compilation of main() without return
How to force gcc compilator throw error when int main() have no return statement. This code compiles without any errors
#include<stdio.h>
int main(){
printf("Hi");
}
I am using
...
-1
votes
0
answers
71
views
How to install and use C library in macOS? [closed]
I'm a beginner in C. I'm using macOS (Sequoia) and vscode.
Let's get to the point, I want to use zip.h library so I installed libzip through homebrew. (brew install libzip)
But my vscode and gcc still ...
-1
votes
0
answers
26
views
is this a new line character input buffer? [duplicate]
enter image description here
when i entered number of columns, after hitting enter got the newline character within the input buffer.
enter image description here
i was expecting this kind of result.
...
2
votes
1
answer
89
views
Listing all permutations as a List in C
Struggling to identify what is wrong with my code. I want to understand why my intuition here is wrong. The reason I want to produce a bunch of list is to hopefully enumerate at the start. But what am ...
4
votes
1
answer
99
views
Segfault even though correct value in variable?
I have the following main.c:
#include <stdio.h>
#include <stdlib.h>
extern unsigned short addsub(int op1, int op2, char what, int *res, int *bit_count);
void print_flags(unsigned short ...
2
votes
0
answers
99
views
How can I force the compiler to keep my parameters in the same registers when returning?
I'm trying to write some weird code that I'm planning on using for a very simple JIT. It's a bunch of small bytecode handler functions that I'll use in the generated executable that will look ...
2
votes
1
answer
78
views
Is it correct to bind UDP and TCP sockets to the same address and handle them simultaneously?
I am trying to bind both UDP and TCP sockets to the same IP address and port, and then handle both types of connections. I have implemented the following code:
The main function initializes both ...
2
votes
4
answers
152
views
Is it well defined to cast generic function pointers to specifc signatures with void* params pointing to different types
EDIT2:
It seems that the standard is not exactly clear, and appears to at least partially contradict itself in different parts on the usage of void* or struct* when casting function pointers.
The lack ...
1
vote
0
answers
96
views
How to know if a segmentation fault will happen? [closed]
I'm new in c programming and i am wondering if there is any sure way to know if a program will segfault.
I came to know about the "valgrind" function but some of my codes still encounter ...
-2
votes
2
answers
82
views
How to copy char data to a smaller char already defined in memory? [closed]
Maybe this is an easy one but i could not find solution.
in function :
int function(char **data)
{
char data_new[542] = {.......};
memcpy(*data, data_new, sizeof(data_new));
return 1;
}
It does not ...
0
votes
0
answers
17
views
Problems with checksum in ICMP packets in C [closed]
I'm trying to create an ICMP timestamp program in C but i am having difficulties with the checksum of the ICMP packet. After doing the checksum of the packet i do the checksum of the packet again ...
2
votes
2
answers
43
views
STM32F4 Multiple motors with cases
Below is the motordriver.c code I’ve written. My goal is to execute a specific scenario where sometimes 3-4 motors need to operate simultaneously. I have arranged this scenario using a case structure. ...
0
votes
0
answers
46
views
How do I decompress the body of a http response in C using Brotli? [closed]
Whenever I try to decompress the body of this HTTP response, BrotliDecoderDecompress returns BROTLI_DECODER_RESULT_ERROR. However, I can't figure out what it is I'm doing wrong here.
// RECIEVE ...
1
vote
2
answers
76
views
error: format ‘%p’ expects argument of type ‘void *’, but argument 2 has type ‘int *’ [-Werror=format=]
Compiling the below code without gcc flags doesn't raise any errors but does when I use -Werror, I have been printing memory address with %p flag but apparently I now have to typecast to void* to use ...
1
vote
0
answers
34
views
Meson can't find libm while cross-compiling
I've written a Meson build script to cross-compile a project.
Right now I have the full thing running but am having trouble finding libm "the proper way".
My toolchain is arm-none-eabi and ...
0
votes
0
answers
68
views
Mario less comfortable task - How to add space without typing in " " [closed]
My code works for the printing of hashes but it doesn't pass the check because of the additional space character(" "). I got the error:
"expected ""#"", not "&...
2
votes
1
answer
91
views
Can you compare two constant pointers in the C preprocessor?
Say my code looks like this:
gpios.h:
#define GPIO_BASE 0x08000100
#define GPIOA ((GpioRegs *) (GPIO_BASE + 0x04))
#define GPIOB ((GpioRegs *) (GPIO_BASE + 0x0C))
#define GPIOC ((GpioRegs *) (...
2
votes
0
answers
92
views
why does Python from C fail to load module?
PyObject *python_module;
char *module_filename = "/mnt/USB3/C/Python_from_C/python_processes";
Py_Initialize();
python_module = PyImport_ImportModule(module_filename);
if(python_module == ...