velox_vulnus

joined 1 year ago
MODERATOR OF
[–] velox_vulnus@lemmy.ml 4 points 14 hours ago* (last edited 14 hours ago)

This worked for me - I think %p fixed the issue of incorrect representation, as well as input. I also tried unsigned long int, which works in place of uintptr_t, but I'm assuming that it isn't portable.

Resolved code snippet

/* Allows the user to view regions of computer memory */

#include <ctype.h>
#include <stdint.h>
#include <stdio.h>

typedef unsigned char BYTE;

int
main (void)
{
  uintptr_t addr;
  int i, n;
  BYTE *ptr;

  printf ("Address of main function: %p\n", (void *) &main);
  printf ("Address of addr variable: %p\n", (void *) &addr);
  printf ("\nEnter a (hex) address: ");
  scanf ("%p", &addr);
  printf ("Enter number of bytes to view: ");
  scanf ("%d", &n);

  printf ("\n");
  printf (" Address               Bytes             Characters\n");
  printf (" ------- ------------------------------- ----------\n");

  ptr = (BYTE *) addr;
  for (; n > 0; n -= 10)
    {
      printf ("%8X  ", (uintptr_t) ptr);
      for (i = 0; i < 10 && i < n; i++)
        printf ("%.2X ", *(ptr + i));
      for (; i < 10; i++)
        printf ("   ");
      printf (" ");
      for (i = 0; i < 10 && i < n; i++)
        {
          BYTE ch = *(ptr + i);
          if (!isprint (ch))
            ch = '.';
          printf ("%c", ch);
        }
      printf ("\n");
      ptr += 10;
    }

  return 0;
}

 

cross-posted from: https://lemmy.ml/post/21033409

In the book authored by K.N.King, there's this example:

viewmemory.c

/* Allows the user to view regions of computer memory */

#include <stdio.h>
#include <ctype.h>

typedef unsigned char BYTE;

int main(void)
{
	unsigned int addr;
	int i, n;
	BYTE *ptr;
	
	printf("Address of main function: %x\n", (unsigned int) main);
	printf("Address of addr variable: %x\n", (unsigned int) &addr);
	printf("\nEnter a (hex) address: ");
	scanf("%x", &addr);
	printf("Enter number of bytes to view: ");
	scanf("%d", &n);
	
	printf("\n");
	printf(" Address               Bytes             Characters\n");
	printf(" ------- ------------------------------- ----------\n");
	
	ptr = (BYTE *) addr;
	for (; n > 0; n -= 10) {
		printf("%8X  ", (unsigned int) ptr);
		for (i = 0; i < 10 && i < n; i++)
			printf("%.2X ", *(ptr + i));
		for (; i < 10; i++)
			printf("   ");
		printf(" ");
		for (i = 0; i < 10 && i < n; i++) {
			BYTE ch = *(ptr + i);
			if (!isprint(ch))
				ch = '.';
			printf("%c", ch);
		}
		printf("\n");
		ptr += 10;
	}
	
	return 0;
}

For some reason, when I try to enter addr variable address as the parameter, it has a segmentation fault error. However, in the book's example and the screenshot from this site in Hangul, there's no such error?

When I try using gdb to check the issue, here's what I get:

gdb

$ gdb ./a.out  --silent
Reading symbols from ./a.out...
(gdb) run
Starting program: /home/<username>/Desktop/c-programming-a-modern-approach/low-level-programming/a.out 
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/gnu/store/zvlp3n8iwa1svxmwv4q22pv1pb1c9pjq-glibc-2.39/lib/libthread_db.so.1".
Address of main function: 401166
Address of addr variable: ffffd678

Enter a (hex) address: ffffd678
Enter number of bytes to view: 64

 Address               Bytes             Characters
 ------- ------------------------------- ----------

Program received signal SIGSEGV, Segmentation fault.
0x000000000040123a in main () at viewmemory.c:31
warning: Source file is more recent than executable.
31	        printf ("%.2X ", *(ptr + i));
(gdb)

What is going on? By the way, I am using Guix, if that matters in any way. Here's the output for ldd:

ldd

$ ldd ./a.out 
	linux-vdso.so.1 (0x00007ffecdda9000)
	libgcc_s.so.1 => /gnu/store/w0i4fd8ivrpwz91a0wjwz5l0b2ralj16-gcc-11.4.0-lib/lib/libgcc_s.so.1 (0x00007fcd2627a000)
	libc.so.6 => /gnu/store/zvlp3n8iwa1svxmwv4q22pv1pb1c9pjq-glibc-2.39/lib/libc.so.6 (0x00007fcd2609c000)

 

In the book authored by K.N.King, there's this example:

viewmemory.c

/* Allows the user to view regions of computer memory */

#include <stdio.h>
#include <ctype.h>

typedef unsigned char BYTE;

int main(void)
{
	unsigned int addr;
	int i, n;
	BYTE *ptr;
	
	printf("Address of main function: %x\n", (unsigned int) main);
	printf("Address of addr variable: %x\n", (unsigned int) &addr);
	printf("\nEnter a (hex) address: ");
	scanf("%x", &addr);
	printf("Enter number of bytes to view: ");
	scanf("%d", &n);
	
	printf("\n");
	printf(" Address               Bytes             Characters\n");
	printf(" ------- ------------------------------- ----------\n");
	
	ptr = (BYTE *) addr;
	for (; n > 0; n -= 10) {
		printf("%8X  ", (unsigned int) ptr);
		for (i = 0; i < 10 && i < n; i++)
			printf("%.2X ", *(ptr + i));
		for (; i < 10; i++)
			printf("   ");
		printf(" ");
		for (i = 0; i < 10 && i < n; i++) {
			BYTE ch = *(ptr + i);
			if (!isprint(ch))
				ch = '.';
			printf("%c", ch);
		}
		printf("\n");
		ptr += 10;
	}
	
	return 0;
}

For some reason, when I try to enter addr variable address as the parameter, it has a segmentation fault error. However, in the book's example and the screenshot from this site in Hangul, there's no such error?

When I try using gdb to check the issue, here's what I get:

gdb

$ gdb ./a.out  --silent
Reading symbols from ./a.out...
(gdb) run
Starting program: /home/<username>/Desktop/c-programming-a-modern-approach/low-level-programming/a.out 
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/gnu/store/zvlp3n8iwa1svxmwv4q22pv1pb1c9pjq-glibc-2.39/lib/libthread_db.so.1".
Address of main function: 401166
Address of addr variable: ffffd678

Enter a (hex) address: ffffd678
Enter number of bytes to view: 64

 Address               Bytes             Characters
 ------- ------------------------------- ----------

Program received signal SIGSEGV, Segmentation fault.
0x000000000040123a in main () at viewmemory.c:31
warning: Source file is more recent than executable.
31	        printf ("%.2X ", *(ptr + i));
(gdb)

What is going on? By the way, I am using Guix, if that matters in any way. Here's the output for ldd:

ldd

$ ldd ./a.out 
	linux-vdso.so.1 (0x00007ffecdda9000)
	libgcc_s.so.1 => /gnu/store/w0i4fd8ivrpwz91a0wjwz5l0b2ralj16-gcc-11.4.0-lib/lib/libgcc_s.so.1 (0x00007fcd2627a000)
	libc.so.6 => /gnu/store/zvlp3n8iwa1svxmwv4q22pv1pb1c9pjq-glibc-2.39/lib/libc.so.6 (0x00007fcd2609c000)

[–] velox_vulnus@lemmy.ml 3 points 2 days ago (1 children)

What do they spy on, the explosive diarrhea?

[–] velox_vulnus@lemmy.ml 23 points 2 days ago

Imagine being offended by "woke" stuff and not actual bigotry. I wonder who's the real snowflake?

[–] velox_vulnus@lemmy.ml 21 points 3 days ago* (last edited 3 days ago)

It's not a success. Two-state solution is a failure. Be it India-Pakistan, East-West Germany, North-South Korea or Sudan-South Sudan.

As someone from India, the two-state solution for India-Pakistan was a massive disaster. One of the worst man-made catastrophe. Rape, murder and violence between different ethnic groups, it was horrible. People were forcibly displaced to the other side of the country, leaving behind their ancestral village and belongings. This destroyed their culture and their language, stripped their identity.

These states were divided to satisfy the egoes of the two major political dynasts, Nehru and Jinnah, and as typical of pretend-socialist liberals, they were supported by the Hindu Mahasabha and the All India Muslim league.

Pakistan forced the use of Urdu, an Indian language, because their native languages had Devanagari-resembling script, and for that strong Muslim identity they went for a language with a Farsi script.... except that the language was Khadi Boli (a language from UP) with borrowed Farsi words.

Well, what about India? They went ballistic sub-nationalist. State majoritarians forced language on vulnerable groups, including mine (obligatory middle-finger to the Basel Mission and Kannada chauvinists).

Later, Pakistan's ethnic cleansing and rape of Bengalis, especially Hindus in East Pakistan (East Bengal) backfired, and the country broke into three. Cut to 2024, the people of Kashmir suffer even to this day.

If only the Indian communists from the HSRA had not been betrayed by the INC, a greater India with none of the communal B.S. would have existed. There would have been no Hindutva or Deobandi extremists jump around and squirming like cockroaches. And we have two countries armed to the brim with nuclear weapons.

[–] velox_vulnus@lemmy.ml 23 points 3 days ago* (last edited 3 days ago) (1 children)

Economically, somewhere between Qatar and Lebanon. Palestine's sea near Gaza has a rich source of oil. They also allow ships to cross through, which is a nice source of income. Culturally, they probably have something in common with the Lebanese and Egyptians.

[–] velox_vulnus@lemmy.ml 88 points 3 days ago* (last edited 3 days ago) (9 children)

Scriptkiddies doing the bare-minimum to profit over other's hard-work. They're not going to survive, because they don't know shit about the internal workings of their product, they won't be able to scale it quickly, and sooner or later, they'll run out of money, if it's not the poor publicity killing their product.

[–] velox_vulnus@lemmy.ml 10 points 4 days ago* (last edited 4 days ago)

I was going to write a lot of stuff about my own experience, but then I decided that it wasn't worth writing and getting my identity exposed, so I'll say "same", minus the disowning part, because I come from a collectivist society. My failure as an mid-20s adult is theirs to blame, because that's how broken I am, and I still can't cope with the past. Tough-love my ass.

 

In my journey to learning C, I've come across header files, which are used to (I'm assuming) define a prototype for the source file, as well as structure modules. This feature, in my opinion, is pointlessly not just redundant, but possibly a source for pitfall. The same information can probably be extracted from the source code, if not for the restrictions of the language specification in C.

Say, if I have a GTK project, I will have to use the preprocessor directive, that will require the use of GTK headers that look something like #include <gtk/gtk.h>, and they're usually in the system path. How do modern languages, like Rust, Zig or Go deal with this situation, where shared libraries are used?

[–] velox_vulnus@lemmy.ml 1 points 1 week ago* (last edited 1 week ago)

Bath towels: Daily (I bath twice in a day)

Bedding: Every week

[–] velox_vulnus@lemmy.ml 2 points 1 week ago* (last edited 1 week ago) (3 children)

I'm interested to see the future of QuickJS, TinyJS and Duktape.

[–] velox_vulnus@lemmy.ml 11 points 1 week ago (9 children)

Systemd: the Biggest Fallacies - point 1 addresses what you're talking about, but remember that this blog is almost a decade old, so by this time, it is not reflective of the current condition.

[–] velox_vulnus@lemmy.ml 4 points 1 week ago* (last edited 1 week ago) (1 children)

There's shepherd for Guix, which I like, to be frank. elogind is seperated, as opposed to logind being a part of the "init" system. There's also alternatives like s6 and runit.

[–] velox_vulnus@lemmy.ml 5 points 1 week ago* (last edited 1 week ago) (1 children)

I was wondering - does the enforcement of no-derivation prevent the applying of patches and file substitutions, while building projects in a substitute build farm? As someone who packages for Guix and requires ELF-patching, I would be violating the new license, right?

 

The instance of XFCE that I am using seems to be really buggy. I am forced to use both xfce-volumed-pulse and xfce-pulseaudio-plugin side by side, and the issue that arises from this is that now there are two notification indicators for the present volume.

When I remove xfce-volumed-pulse (this plugin is no longer shown on the official documentation), the multimedia key stops working, so there's no notification indicator.

But when I remove xfce-pulseaudio-plugin, I am no longer able to access the slider widget in the control panel, that allows me to tap into pavucontrol.

What is happening here?

view more: next ›